question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected IndexError exception on malformed input

See original GitHub issue

When running the following code with the latest version of asn1crypto on the attached input in an unexpected IndexError exception:

import sys
from asn1crypto.core import Sequence

with open(sys.argv[1], 'rb') as f:
    data = f.read()
parsed = Sequence.load(data)
parsed.copy()  # force parsing
parsed.dump(force=True)
$ python3 asn2crypto_repro.py testcase.txt
Traceback (most recent call last):
  File "asn2crypto_repro.py", line 6, in <module>
    parsed = Sequence.load(data)
  File "/home/user/.local/lib/python3.8/site-packages/asn1crypto/core.py", line 230, in load
    value, _ = _parse_build(encoded_data, spec=spec, spec_params=kwargs, strict=strict)
  File "/home/user/.local/lib/python3.8/site-packages/asn1crypto/core.py", line 5668, in _parse_build
    info, new_pointer = _parse(encoded_data, encoded_len, pointer)
  File "/home/user/.local/lib/python3.8/site-packages/asn1crypto/parser.py", line 175, in _parse
    num = ord(encoded_data[pointer]) if _PY2 else encoded_data[pointer]
IndexError: index out of range

test.txt

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
wbondcommented, Nov 9, 2020

I think we can improve the parse functions to be sure to raise a ValueError

0reactions
joernheisslercommented, Nov 9, 2020

IndexError isn’t a ValueError.

whoops 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Which exception should I raise on bad/illegal argument ...
Used when keyword arguments are missing that were required for the specific call, or argument values are individually valid but inconsistent with each...
Read more >
Malformed input or input contains unmappable characters
Malformed input or input contains unmappable characters. Problem. Errors/failures in the Git Integration for Jira application indexing. Diagnosis.
Read more >
Git Integration for Jira Server - Confluence - Atlassian
Enable the Git Integration for Jira app in Jira Administration → Manage apps. Start a reindex of the Git Integration for Jira app....
Read more >
Bug listing with status RESOLVED with resolution TEST ...
... moves unexpectedly" status:RESOLVED resolution:TEST-REQUEST severity:major ... Bug:93685 - "app-office/lyx kyb input errors for accented characters" ...
Read more >
Lecture 1
Exceptions do not occur because of a malformed Python statement or program but ... Examples include those demonstrated above: ZeroDivisionError, IndexError, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found