Skip to content

xmlrpc.client.loads raises IndexError on a malformed struct #153803

Description

@tonghuaroot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions