8000 0.5.0 regression - OverflowError: cannot fit 'int' into an index-sized integer · Issue #54 · pyasn1/pyasn1 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

0.5.0 regression - OverflowError: cannot fit 'int' into an index-sized integer #54

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

Open
adiroiban opened this issue Jan 24, 2024 · 5 comments

Comments

@adiroiban
Copy link

Thanks for this great library :)

I am upgrading from 0.4.8 to 0.5.1.

While executing my tests I can see that with 0.5.0 (and 0.5.1) the pyasn1.error.SubstrateUnderrunError is no longer raised and instead an OverflowError is raised.

To reproduce, I have this code.

Data is just some random input.

from pyasn1.codec.ber import decoder
data = b'\xa6\x08\'\x9b\xb1\x01\'8\x19\xa3\x1f\xf3\xf181R\xa2\xd84"\x82\x9eu4~\x8d\xaa\x0f\xc3\x0e2\xbb\xa0hF\xb7\x05\xa7\x01U9\xf4\xc8+.\x98\x9a8\x94\xdbx]\xbb\xd6\x98w\xe9\xb1\xb0\xe9\xd9\x96:7$'
decoder.decode(data)

The error is

>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/ber/decoder.py", line 2063, in __call__
    for asn1Object in streamingDecoder:
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/ber/decoder.py", line 1932, in __iter__
    for asn1Object in self._singleItemDecoder(
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/ber/decoder.py", line 1788, in __call__
    for value in concreteDecoder.valueDecoder(
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/ber/decoder.py", line 102, in valueDecoder
    for value in decodeFun(substrate, asn1Spec, tagSet, length, **options):
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/ber/decoder.py", line 1788, in __call__
    for value in concreteDecoder.valueDecoder(
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/ber/decoder.py", line 333, in valueDecoder
    for component in decodeFun(
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/ber/decoder.py", line 1788, in __call__
    for value in concreteDecoder.valueDecoder(
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/ber/decoder.py", line 97, in valueDecoder
    for chunk in substrateFun(asn1Object, substrate, length, options):
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/ber/decoder.py", line 73, in substrateCollector
    for chunk in readFromStream(substrate, length, options):
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/streaming.py", line 228, in readFromStream
    received = substrate.read(size)
               ^^^^^^^^^^^^^^^^^^^^
OverflowError: cannot fit 'int' into an index-sized integer

Note that if you try a smaller input you get

>>> decoder.decode(data[:63])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/VENV-PATH/lib/python3.11/site-packages/pyasn1/codec/ber/decoder.py", line 2005, in __call__
    raise error.SubstrateUnderrunError('Short substrate on input')
pyasn1.error.SubstrateUnderrunError: Short substrate on input
@adiroiban
Copy link
Author

I think that this change was introduced at 93e11a2

@adiroiban
Copy link
Author

I see this code which seems that it does not validation for the length

I am not sure at which level this should be fixed

encodedLength = list(encodedLength)
# missing check on maximum size, which shouldn't be a
# problem, we can handle more than is possible
if len(encodedLength) != size:
raise error.SubstrateUnderrunError(
'%s<%s at %s' % (size, len(encodedLength), tagSet)
)
length = 0
for lengthOctet in encodedLength:
length <<= 8
length |= oct2int(lengthOctet)
size += 1

@droideck
Copy link
droideck commented Feb 8, 2024

@adiroiban, could you please provide more context about the "random" input data you try to decode?

data = b'\xa6\x08\'\x9b\xb1\x01\'8\x19\xa3\x1f\xf3\xf181R\xa2\xd84"\x82\x9eu4~\x8d\xaa\x0f\xc3\x0e2\xbb\xa0hF\xb7\x05\xa7\x01U9\xf4\xc8+.\x98\x9a8\x94\xdbx]\xbb\xd6\x98w\xe9\xb1\xb0\xe9\xd9\x96:7$'

@adiroiban
Copy link
Author

Hi. The data is just random. Is a private key for which the wrong decryption secret was used...so ended up with data without any meaning.

@droideck
Copy link
droideck commented Feb 8, 2024

Hi. The data is just random. Is a private key for which the wrong decryption secret was used...so ended up with data without any meaning.

Okay, the issue is minor then, and I'll check it later when time allows. Thank you for the report!

Or, as usual, PRs are welcome! :)

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

No branches or pull requests

2 participants
0