Skip to content

Commit 8fc66ae

Browse files
gh-148395: Fix a possible UAF in {LZMA,BZ2,_Zlib}Decompressor (GH-148396)
Fix dangling input pointer after `MemoryError` in _lzma/_bz2/_ZlibDecompressor.decompress
1 parent 480edc1 commit 8fc66ae

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-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`, and internal :class:`!zlib._ZlibDecompressor`
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
@@ -571,6 +571,7 @@ decompress(BZ2Decompressor *d, char *data, size_t len, Py_ssize_t max_length)
571571
return result;
572572

573573
error:
574+
bzs->next_in = NULL;
574575
Py_XDECREF(result);
575576
return NULL;
576577
}

Modules/_lzmamodule.c

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

11021102
error:
1103+
lzs->next_in = NULL;
11031104
Py_XDECREF(result);
11041105
return NULL;
11051106
}

Modules/zlibmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,7 @@ decompress(ZlibDecompressor *self, uint8_t *data,
16691669
return result;
16701670

16711671
error:
1672+
self->zst.next_in = NULL;
16721673
Py_XDECREF(result);
16731674
return NULL;
16741675
}

0 commit comments

Comments
 (0)