Skip to content

Commit 1d3eab6

Browse files
committed
gh-158583: Fix uninitialized memory read in bytes.fromhex()
1 parent ab01d18 commit 1d3eab6

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎Objects/bytesobject.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,9 +2685,10 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray)
26852685
if (Py_ISSPACE(*str)) {
26862686
do {
26872687
str++;
2688+
if (str >= end) {
2689+
goto done;
2690+
}
26882691
} while (Py_ISSPACE(*str));
2689-
if (str >= end)
2690-
break;
26912692
}
26922693

26932694
top = _PyLong_DigitValue[*str];
@@ -2696,6 +2697,9 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray)
26962697
goto error;
26972698
}
26982699
str++;
2700+
if (str >= end) {
2701+
break;
2702+
}
26992703

27002704
bot = _PyLong_DigitValue[*str];
27012705
if (bot >= 16) {
@@ -2712,6 +2716,7 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray)
27122716
*buf++ = (unsigned char)((top << 4) + bot);
27132717
}
27142718

2719+
done:
27152720
if (view.obj != NULL) {
27162721
PyBuffer_Release(&view);
27172722
}

0 commit comments

Comments
 (0)