Skip to content

Commit 47128e6

Browse files
[3.10] gh-148395: Fix a possible UAF in {LZMA,BZ2}Decompressor (GH-148396) (#148505)
Fix dangling input pointer after `MemoryError` in _lzma/_bz2/_ZlibDecompressor.decompress (cherry picked from commit 8fc66ae)
1 parent c5767a7 commit 47128e6

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fix a dangling input pointer in :class:`lzma.LZMADecompressor`,
2+
:class:`bz2.BZ2Decompressor`
3+
when memory allocation fails with :exc:`MemoryError`, which could let a
4+
subsequent :meth:`!decompress` call read or write through a stale pointer to
5+
the already-released caller buffer.

Modules/_bz2module.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ decompress(BZ2Decompressor *d, char *data, size_t len, Py_ssize_t max_length)
595595
return result;
596596

597597
error:
598+
bzs->next_in = NULL;
598599
Py_XDECREF(result);
599600
return NULL;
600601
}

Modules/_lzmamodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ decompress(Decompressor *d, uint8_t *data, size_t len, Py_ssize_t max_length)
11021102
return result;
11031103

11041104
error:
1105+
lzs->next_in = NULL;
11051106
Py_XDECREF(result);
11061107
return NULL;
11071108
}

0 commit comments

Comments
 (0)