]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-88116: Avoid undefined behavior when decoding varints in code objects (#94375)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Tue, 28 Jun 2022 13:24:54 +0000 (14:24 +0100)
committerGitHub <noreply@github.com>
Tue, 28 Jun 2022 13:24:54 +0000 (14:24 +0100)
Misc/NEWS.d/next/Core and Builtins/2022-06-28-12-41-17.gh-issue-88116.A7fEl_.rst [new file with mode: 0644]
Objects/codeobject.c

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 (file)
index 0000000..a8347cf
--- /dev/null
@@ -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
index c38c51b45321c1b1a2362603d5535f5eee52f3db..6f2a837240384662093663f99c2eeec9af638ce9 100644 (file)
@@ -354,9 +354,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;
@@ -368,7 +368,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);
     }
@@ -847,9 +847,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;
@@ -861,7 +861,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);
     }