Skip to content

gh-151532: Validate xmlrpc.client.dumps() arguments under -O#151533

Open
zainnadeem786 wants to merge 1 commit into
python:mainfrom
zainnadeem786:gh-151532-xmlrpc-dumps-validation-clean
Open

gh-151532: Validate xmlrpc.client.dumps() arguments under -O#151533
zainnadeem786 wants to merge 1 commit into
python:mainfrom
zainnadeem786:gh-151532-xmlrpc-dumps-validation-clean

Conversation

@zainnadeem786

Copy link
Copy Markdown

Summary

Fixes gh-151532.

xmlrpc.client.dumps() currently uses assert statements to validate public API arguments. When Python is executed with optimization enabled (python -O), those assertions are removed, causing invalid inputs to be accepted and serialized instead of being rejected.

This change replaces the assertion-based validation with explicit runtime checks so behavior remains consistent regardless of optimization mode.

Reproduction

Before this change:

import xmlrpc.client as xmlrpclib

xmlrpclib.dumps(["x"])

Normal execution:

AssertionError: argument must be tuple or Fault instance

Optimized execution (python -O):

No exception raised

Similarly:

xmlrpclib.dumps((1, 2), methodresponse=True)

Normal execution:

AssertionError: response tuple must be a singleton

Optimized execution (python -O):

No exception raised

Because the validation relied on assertions, invalid inputs were silently accepted when optimization was enabled.

Changes

  • Replace the assert that validates params with an explicit TypeError.
  • Replace the assert that validates methodresponse=True response tuples with an explicit ValueError.
  • Preserve the existing validation messages.
  • Add regression tests covering invalid argument types and invalid response tuple lengths.
  • Add an optimized (python -O) subprocess test to verify validation remains enforced when assertions are disabled.
  • Add a NEWS entry.

Tests

Added regression coverage for:

  • Invalid params values (list, dict, str, int)
  • Invalid methodresponse=True tuple lengths
  • Validation behavior under python -O

After this change, invalid inputs are rejected consistently in both normal and optimized execution modes.

Issue: gh-151532

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xmlrpc.client.dumps() skips argument validation when Python is run with -O

1 participant