[ 
https://issues.apache.org/jira/browse/PROTON-2244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17150250#comment-17150250
 ] 

ASF GitHub Bot commented on PROTON-2244:
----------------------------------------

kpvdr commented on a change in pull request #263:
URL: https://github.com/apache/qpid-proton/pull/263#discussion_r448980074



##########
File path: c/src/core/encoder.c
##########
@@ -336,8 +336,10 @@ static int pni_encoder_exit(void *ctx, pn_data_t *data, 
pni_node_t *node)
   pn_encoder_t *encoder = (pn_encoder_t *) ctx;
   char *pos;
 
-  // Special case 0 length list
-  if (node->atom.type==PN_LIST && node->children-encoder->null_count==0) {
+  // Special case 0 length list, but not as first element in an array
+  pni_node_t *parent = pn_data_node(data, node->parent);
+  if (node->atom.type==PN_LIST && node->children-encoder->null_count==0 &&
+      !(pn_is_in_array(data, parent, node) && pn_is_first_in_array(data, 
parent, node))) {

Review comment:
       Agreed. You are correct, this needs to happen for ALL list array members 
that are empty. I have checked in an update and tested it with empty lists as 
several members of the array including first, and all now work correctly.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


> [Proton-c] Encoder error for array of lists where first list in array is empty
> ------------------------------------------------------------------------------
>
>                 Key: PROTON-2244
>                 URL: https://issues.apache.org/jira/browse/PROTON-2244
>             Project: Qpid Proton
>          Issue Type: Task
>          Components: proton-c
>            Reporter: Kim van der Riet
>            Priority: Major
>
> AMQP encodes arrays with a single element constructor which should be 
> identical for all elements in the array. However, if an array of lists is 
> constructed in which the first list is empty, then the AMQP empty list 
> constructor is used in the array, and the following lists which may be 
> non-empty, will not be decoded correctly.
> {noformat}
> >>> import proton
> >>> a = proton.Array(proton.UNDESCRIBED, proton.Data.LIST, [], [1,2,3], 
> >>> ['aaa', 'bbb', 'ccc'])
> >>> d1 = proton.Data()
> >>> d1.put_py_array(a)
> >>> d1.encode().hex()
> 'f00000002a00000003450000000a000000035501550255030000001300000003a103616161a103626262a103636363'
> {noformat}
> which, when broken down into parts, looks as follows:
> {noformat}
> f0 000002a 00000003 45 <-- Array constructor, size=0x2a, len=3, type=empty 
> list
>                     ^^--- Empty list constructor
> 0000000a 00000003 5501 5502 5503 <- data for [1,2,3]
> 00000013 00000003 a103616161 a103626262 a103636363 <-- data for ['aaa', 
> 'bbb', 'ccc']
> {noformat}
> When decoded, this is being interpreted as an array of empty lists:
> {noformat}
> >>> d2 = proton.Data()
> >>> d2.decode(d1.encode())
> 10
> >>> d2.get_py_array()
> Array(UNDESCRIBED, 24, [], [], [])
> {noformat}
> When a mis-encoded array is used in the body of a message and is decoded, an 
> error results:
> {noformat}
> >>> import proton
> >>> a = proton.Array(proton.UNDESCRIBED, proton.Data.LIST, [], [1,2,3], 
> >>> ['aaa', 'bbb', 'ccc'])
> >>> m1 = proton.Message(body=a)
> >>> m1
> Message(priority=4, body=Array(UNDESCRIBED, 24, [], [1, 2, 3], ['aaa', 'bbb', 
> 'ccc']))
> >>> m2 = proton.Message()
> >>> m2.decode(m1.encode())
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File 
> "/home/kvdr/RedHat/install/lib64/proton/bindings/python3/proton/_message.py", 
> line 488, in decode
>  self._check(pn_message_decode(self._msg, data))
>  File 
> "/home/kvdr/RedHat/install/lib64/proton/bindings/python3/proton/_message.py", 
> line 87, in _check
>  raise exc("[%s]: %s" % (err, pn_error_text(pn_message_error(self._msg))))
> proton._exceptions.MessageException: [-6]: data error: (null)
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to