diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-06-28 13:54:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 13:54:30 (GMT) |
commit | 50a2e36ce9097b0f376780e2f996c30936095eec (patch) | |
tree | 34894bf789b3f10ed92657b83edc986b016eaa57 | |
parent | 648469299d9102bcc165baace67c6758e244eec1 (diff) | |
download | cpython-50a2e36ce9097b0f376780e2f996c30936095eec.zip cpython-50a2e36ce9097b0f376780e2f996c30936095eec.tar.gz cpython-50a2e36ce9097b0f376780e2f996c30936095eec.tar.bz2 |
gh-88116: Avoid undefined behavior when decoding varints in code objects (GH-94375)
(cherry picked from commit c485ec014ce174bb3f5ae948151dc40e0f6d5f7f)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2022-06-28-12-41-17.gh-issue-88116.A7fEl_.rst | 2 | ||||
-rw-r--r-- | Objects/codeobject.c | 16 |
2 files changed, 10 insertions, 8 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-28-12-41-17.gh-issue-88116.A7fEl_.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-28-12-41-17.gh-issue-88116.A7fEl_.rst new file mode 100644 index 0000000..a8347cf --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-28-12-41-17.gh-issue-88116.A7fEl_.rst @@ -0,0 +1,2 @@ +Fix an issue when reading line numbers from code objects if the encoded line +numbers are close to ``INT_MIN``. Patch by Pablo Galindo diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 8b9ca89..b23756b 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -346,9 +346,9 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con) static int scan_varint(const uint8_t *ptr) { - int read = *ptr++; - int val = read & 63; - int shift = 0; + unsigned int read = *ptr++; + unsigned int val = read & 63; + unsigned int shift = 0; while (read & 64) { read = *ptr++; shift += 6; @@ -360,7 +360,7 @@ scan_varint(const uint8_t *ptr) static int scan_signed_varint(const uint8_t *ptr) { - int uval = scan_varint(ptr); + unsigned int uval = scan_varint(ptr); if (uval & 1) { return -(int)(uval >> 1); } @@ -839,9 +839,9 @@ read_byte(PyCodeAddressRange *bounds) static int read_varint(PyCodeAddressRange *bounds) { - int read = read_byte(bounds); - int val = read & 63; - int shift = 0; + unsigned int read = read_byte(bounds); + unsigned int val = read & 63; + unsigned int shift = 0; while (read & 64) { read = read_byte(bounds); shift += 6; @@ -853,7 +853,7 @@ read_varint(PyCodeAddressRange *bounds) static int read_signed_varint(PyCodeAddressRange *bounds) { - int uval = read_varint(bounds); + unsigned int uval = read_varint(bounds); if (uval & 1) { return -(int)(uval >> 1); } |