Skip to content

Commit 6a5f79c

Browse files
[3.14] gh-148395: Fix a possible UAF in {LZMA,BZ2,_Zlib}Decompressor (GH-148396) (#148480)
gh-148395: Fix a possible UAF in `{LZMA,BZ2,_Zlib}Decompressor` (GH-148396) Fix dangling input pointer after `MemoryError` in _lzma/_bz2/_ZlibDecompressor.decompress (cherry picked from commit 8fc66ae) Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 48c3c7f commit 6a5f79c

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
@@ -593,6 +593,7 @@ decompress(BZ2Decompressor *d, char *data, size_t len, Py_ssize_t max_length)
593593
return result;
594594

595595
error:
596+
bzs->next_in = NULL;
596597
Py_XDECREF(result);
597598
return NULL;
598599
}

Modules/_lzmamodule.c

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

11221122
error:
1123+
lzs->next_in = NULL;
11231124
Py_XDECREF(result);
11241125
return NULL;
11251126
}

Modules/zlibmodule.c

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

16771677
error:
1678+
self->zst.next_in = NULL;
16781679
Py_XDECREF(result);
16791680
return NULL;
16801681
}

0 commit comments

Comments
 (0)