Skip to content

Commit

Permalink
fix typecode decoding DoS
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Aug 5, 2021
1 parent f166033 commit f6254ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rencode/_rencode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ cdef decode(char *data, unsigned int *pos, long long data_length):
return decode_fixed_dict(data, pos, data_length)
elif typecode == CHR_DICT:
return decode_dict(data, pos, data_length)
else:
raise Exception("invalid typecode %i" % typecode)

def loads(data):
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_rencode.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,14 @@ def test_version_exposed(self):
assert rencode_orig.__version__
self.assertEqual(rencode.__version__[1:], rencode_orig.__version__[1:], "version number does not match")

def test_invalidtypecode(self):
s = b';\x2f\x7f'
try:
rencode.loads(s)
except Exception:
pass
else:
raise Exception("invalid typecode should raise an Exception")

if __name__ == '__main__':
unittest.main()

0 comments on commit f6254ab

Please sign in to comment.