python / python/cpython

xmlrpc.client.loads raises IndexError on a malformed struct

Open
#153,803 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug description

xmlrpc.client.loads() raises a raw IndexError instead of xmlrpc.client.ResponseError when unmarshalling a <struct> that contains a <member> with a <name> but no <value>.

Unmarshaller.end_struct iterates the stacked items in pairs (items[i], items[i+1]). A <member> missing its <value> leaves an odd number of items, so items[i+1] raises IndexError.

The unmarshaller already raises ResponseError for sibling malformed cases (empty stack at line 640, unknown tag inside <data> at line 663).

Reproducer:

import xmlrpc.client

data = (b'<?xml version="1.0"?>'
        b'<methodResponse><params><param><value>'
        b'<struct><member><name>k</name></member></struct>'
        b'</value></param></params></methodResponse>')

xmlrpc.client.loads(data)
# IndexError: list index out of range

Expected: xmlrpc.client.ResponseError.

CPython versions tested on

3.13, 3.14, 3.15, main

Operating systems tested on

macOS

Linked PRs
  • gh-153805

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Unmarshaller.end_struct, where the issue identifies the pairwise iteration that raises IndexError, and compare it with the existing malformed-input handling around lines 640 and 663. Done means the reproducer raises xmlrpc.client.ResponseError rather than IndexError; linked PR gh-153805 indicates that work is already underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.