xmlrpc.client.dumps() skips argument validation when Python is run with -O
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Lies Lib/xmlrpc/client.py und reproduziere das Verhalten mit dem bereitgestellten Skript sowohl bei normaler Ausführung als auch bei der Ausführung mit -O. Untersuche die Validierung in dumps() und füge anschließend Regressionstests für ungültige Parameter und Antworten mit mehreren Werten hinzu, damit das Verhalten unter Optimierung konsistent bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Bug report
Bug description:
Bug description
xmlrpc.client.dumps() currently relies on assert statements to validate public API arguments.
As a result, invalid inputs are rejected in normal execution, but the validation is silently removed when Python is run with optimization (-O), causing different runtime behavior for the same API.
The documentation states that:
paramsmust be a tuple orFaultinstance.methodresponse=Trueexpects a singleton response tuple.
However, these constraints are enforced only through assert, which is removed when __debug__ is false.
Reproducer
import xmlrpc.client as xmlrpclib
for label, call in [
("list params", lambda: xmlrpclib.dumps(["x"])),
("dict params", lambda: xmlrpclib.dumps({"x": 1})),
("string params", lambda: xmlrpclib.dumps("abc")),
("multi-value response", lambda: xmlrpclib.dumps((1, 2), methodresponse=True)),
]:
try:
result = call()
except BaseException as exc:
print(label + ":", type(exc).__name__, str(exc))
else:
print(label + ": OK")
Normal execution
python repro.py
Output:
list params: AssertionError argument must be tuple or Fault instance
dict params: AssertionError argument must be tuple or Fault instance
string params: AssertionError argument must be tuple or Fault instance
multi-value response: AssertionError response tuple must be a singleton
Optimized execution
python -O repro.py
Output:
list params: OK
dict params: OK
string params: OK
multi-value response: OK
Root cause
Lib/xmlrpc/client.py currently performs argument validation using assertions:
assert isinstance(params, (tuple, Fault)), \
"argument must be tuple or Fault instance"
assert len(params) == 1, \
"response tuple must be a singleton"
When Python is executed with -O, these assertions are removed and execution proceeds into the marshalling logic, which serializes the supplied values instead of rejecting them.
Expected behavior
Public API validation should be enforced consistently regardless of optimization mode.
Invalid values should continue to be rejected when Python is run with -O.
Actual behavior
Running under -O disables validation and allows invalid inputs to be serialized.
Suggested fix
Replace the assertion-based validation with explicit runtime checks.
Possible exception types:
TypeErrorwhenparamsis neither a tuple nor aFaultinstance.ValueErrorwhenmethodresponse=Trueis used with a tuple length other than 1.
Add regression tests to ensure behavior remains consistent under optimization.
Notes
I searched for existing issues and did not find an open report covering this specific -O behavior difference for xmlrpc.client.dumps().
This appears to be a public API consistency bug rather than a security issue.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows
Linked PRs
- gh-151533
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 558
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/cpython
-
docs pending
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
stdlib type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
stdlib type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
build type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
stdlib topic-email type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Ähnliche Issues
-
area/auth bug comp/agent P3 platform/discord type/security
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
NousResearch/hermes-agent#117848 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
bancolombia/sentinel#23 ·
-
test md OffenCI
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100