xmlrpc icon indicating copy to clipboard operation
xmlrpc copied to clipboard

Fix array parsing when one element is without type identifier

Open aler9 opened this issue 4 years ago • 1 comments

Hello, i stumbled across a response that xmlrpc is unable to decode correctly:

<value><array><data>
  <value><int>5</int></value>
  <value></value>
  <value><string>A</string></value>
</data></array></value>

This is a 3-elements array containing respectively:

  • an int
  • a value without the type identifier, which according to the XML-RPC specification is acceptable (http://xmlrpc.scripting.com/spec.html), and is also normally handled by xmlrpc (https://github.com/kolo/xmlrpc/blob/master/decoder_test.go#L138)
  • a string

The library decodes the XML into a 2-elements slice:

{ 5, nil }

I did some tests, and i discovered that, when decoding a slice, the library does not decode correctly the element immediately after an element without the type identifier. That's due to this sequence of events:

  1. the slice decoder calls dec.Token() and reads a token (<value>) https://github.com/kolo/xmlrpc/blob/master/decoder.go#L248

  2. the slice decoder calls dec.decodeValue() https://github.com/kolo/xmlrpc/blob/master/decoder.go#L266

  3. dec.decodeValue() calls dec.Token() and reads a token, expecting to find the starting tag of a type identifier (i.e. <string>), but instead it finds </value>, and returns nil, since it's an EndElement https://github.com/kolo/xmlrpc/blob/master/decoder.go#L89

  4. the slice decoder calls dec.Skip(), which normally should read any tag up to </value>, but since </value> has already been processed, it goes on and reads the next <value>, <string>, </string>, </value>, so the next array element is totally skipped: https://github.com/kolo/xmlrpc/blob/master/decoder.go#L278

This patch fixes the problem, by skipping dec.Skip() when this problem arises. I also added a unit test.

aler9 avatar Nov 04 '19 22:11 aler9

I'll try to get to this by the end of the week.

icholy avatar Nov 05 '19 01:11 icholy