mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gh-88116: Avoid undefined behavior when decoding varints in code objects (#94375)
This commit is contained in:
parent
44fa03d748
commit
c485ec014c
2 changed files with 10 additions and 8 deletions
|
@ -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
|
|
@ -354,9 +354,9 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
|
||||||
static int
|
static int
|
||||||
scan_varint(const uint8_t *ptr)
|
scan_varint(const uint8_t *ptr)
|
||||||
{
|
{
|
||||||
int read = *ptr++;
|
unsigned int read = *ptr++;
|
||||||
int val = read & 63;
|
unsigned int val = read & 63;
|
||||||
int shift = 0;
|
unsigned int shift = 0;
|
||||||
while (read & 64) {
|
while (read & 64) {
|
||||||
read = *ptr++;
|
read = *ptr++;
|
||||||
shift += 6;
|
shift += 6;
|
||||||
|
@ -368,7 +368,7 @@ scan_varint(const uint8_t *ptr)
|
||||||
static int
|
static int
|
||||||
scan_signed_varint(const uint8_t *ptr)
|
scan_signed_varint(const uint8_t *ptr)
|
||||||
{
|
{
|
||||||
int uval = scan_varint(ptr);
|
unsigned int uval = scan_varint(ptr);
|
||||||
if (uval & 1) {
|
if (uval & 1) {
|
||||||
return -(int)(uval >> 1);
|
return -(int)(uval >> 1);
|
||||||
}
|
}
|
||||||
|
@ -847,9 +847,9 @@ read_byte(PyCodeAddressRange *bounds)
|
||||||
static int
|
static int
|
||||||
read_varint(PyCodeAddressRange *bounds)
|
read_varint(PyCodeAddressRange *bounds)
|
||||||
{
|
{
|
||||||
int read = read_byte(bounds);
|
unsigned int read = read_byte(bounds);
|
||||||
int val = read & 63;
|
unsigned int val = read & 63;
|
||||||
int shift = 0;
|
unsigned int shift = 0;
|
||||||
while (read & 64) {
|
while (read & 64) {
|
||||||
read = read_byte(bounds);
|
read = read_byte(bounds);
|
||||||
shift += 6;
|
shift += 6;
|
||||||
|
@ -861,7 +861,7 @@ read_varint(PyCodeAddressRange *bounds)
|
||||||
static int
|
static int
|
||||||
read_signed_varint(PyCodeAddressRange *bounds)
|
read_signed_varint(PyCodeAddressRange *bounds)
|
||||||
{
|
{
|
||||||
int uval = read_varint(bounds);
|
unsigned int uval = read_varint(bounds);
|
||||||
if (uval & 1) {
|
if (uval & 1) {
|
||||||
return -(int)(uval >> 1);
|
return -(int)(uval >> 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue