[ 
https://issues.apache.org/jira/browse/QPID-498?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12507632
 ] 

Jimmy John commented on QPID-498:
---------------------------------

Thanks for the comments...

The intention of adding the exceptions like SyntaxErrorException, 
FrameErrorException etc into the codec.py script was that they would be caught 
some place upstream and display the appropriate error message, close connection 
etc. e.g. the connection.write function calls the encode functions. The 
function should be within a try/except block so that in case codec.py threw an 
exception, it could take the appropriate action. This handler function can be 
common so that it does the required action whenever it catches an exception.

The issue is that one can never tell if a bad value has been read off the wire 
or not...e.g

>>> struct.pack("!H", 65538)
'\x00\x02'

65538 is an invalid value for a short. When we try and unpack it:

>>> struct.unpack("!H", '\x00\x02')
(2,)

We get a 2 i.e. we can never know if the client was trying to send us a valid 2 
or an invalid 65538. So one would never know that a value read of the pipe is 
invalid or not, unless we catch it at encoding time and raise an exception.



Buy yes, if you look at codec.py standalone, then raising a 
SyntaxErrorException dosen't make much sense. But in the context of the 
client-server interactions, if codec.py throws an exception, then there is some 
value in it. If we define our own exceptions, then when it is caught upstream 
and displayed to the user, it will not be matching the amqp specification. 

Regarding you coment about not including version specific code into the 
codebase, i think we can still use all the exceptions defined and still staisfy 
this criteria. exceptions.py would probably need to be re-written so it reads 
data of spec.py rather than reading hard coded values from constants.py. So in 
future even if the spec changes, exceptions.py will have the correct text. 
[need to get rid of constants.py. I didn't know what spec.py was doing when i 
coded these changes :)]

thots...?





> python code.py handling of data types beyond acceptable range.
> --------------------------------------------------------------
>
>                 Key: QPID-498
>                 URL: https://issues.apache.org/jira/browse/QPID-498
>             Project: Qpid
>          Issue Type: Bug
>          Components: Python Client
>            Reporter: Jimmy John
>            Assignee: Rafael H. Schloming
>            Priority: Minor
>         Attachments: codec.py, constants.py, exception.py
>
>
> Perform range checking on all data types such as octet[0,255], 
> short[0,65535], long etc. [Refer QPID-497 for unit test that detects these 
> bugs]

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to