Skip to content

Commit e20c6c9

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

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+
and :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
@@ -1105,6 +1105,7 @@ decompress(Decompressor *d, uint8_t *data, size_t len, Py_ssize_t max_length)
11051105
return result;
11061106

11071107
error:
1108+
lzs->next_in = NULL;
11081109
Py_XDECREF(result);
11091110
return NULL;
11101111
}

0 commit comments

Comments
 (0)