Skip to content

Commit

Permalink
Merge pull request #298 from ks888/fix-value-error
Browse files Browse the repository at this point in the history
Check the unicode code point range before unichr() is called
  • Loading branch information
etrepum committed Apr 21, 2022
2 parents 02221b1 + 4eee720 commit d8cee7b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions simplejson/decoder.py
Expand Up @@ -109,6 +109,8 @@ def py_scanstring(s, end, encoding=None, strict=True,
uni = int(esc, 16)
except ValueError:
raise JSONDecodeError(msg, s, end - 1)
if uni < 0 or uni > _maxunicode:
raise JSONDecodeError(msg, s, end - 1)
end += 5
# Check for surrogate pair on UCS-4 systems
# Note that this will join high/low surrogate pairs
Expand Down
2 changes: 2 additions & 0 deletions simplejson/tests/test_scanstring.py
Expand Up @@ -132,6 +132,8 @@ def _test_scanstring(self, scanstring):
self.assertRaises(ValueError,
scanstring, '\\ud834\\x0123"', 0, None, True)

self.assertRaises(json.JSONDecodeError, scanstring, "\\u-123", 0, None, True)

def test_issue3623(self):
self.assertRaises(ValueError, json.decoder.scanstring, "xxx", 1,
"xxx")
Expand Down

0 comments on commit d8cee7b

Please sign in to comment.