Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix. Decode Unsigned Values as Unsigned #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nigredon1991
Copy link

Fix some issues in pysnmp

etingof/pysnmp#190
etingof/pysnmp#357
etingof/pysnmp#384

Example for fast test:

from pyasn1.codec.ber import decoder
from pysnmp.hlapi import *

print(decoder.decode(bytes.fromhex('4104985D4B44'), Counter32()))

On the current master, it will fall into a ValueConstraintError:

pyasn1.type.error.ValueConstraintError: <ConstraintsIntersection object, consts <ValueRangeConstraint object, consts 0, 4294967295>> failed at: ValueConstraintError('<ValueRangeConstraint object, consts 0, 4294967295> failed at: ValueConstraintError(-1738716348)') at Counter32

And after correction it is correctly decoded:

(<Counter32 value object, tagSet <TagSet object, tags 64:0:1>, subtypeSpec <ConstraintsIntersection object, consts <ValueRangeConstraint object, consts 0, 4294967295>>, payload [2556250948]>, b'')

@Gerhardzz
Copy link

The value that you decode in the example - '4104985D4B44': leaving the type(41) and the len(04) aside the highest bit of the actual value (985D4B44) is 1. Doesn't that require to handle it as a 2s-complement? because Snmp uses ASN.1/BER and ASN.1 knows signed integer only? In that case the exception would be correct because the server actually used an incorrect encoding and sent a negative number (that's at least my current understanding, also https://pysnmp.readthedocs.io/en/latest/faq/ignored-snmp-packets.html).
Based on which RFC or standard do you now change that behavior?
BR, Gerhard.

@nigredon1991
Copy link
Author

nigredon1991 commented Jul 5, 2023

This behavior is wrong, I'll try to refer to the answer of another person who has already answered quite fully

@lextm
Copy link

lextm commented Feb 11, 2024

Since the ecosystem moved away from here, you should send your pull request to https://github.com/pyasn1/pyasn1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants