Skip to content

Commit c3cf71c

Browse files
[3.13] gh-148395: Fix a possible UAF in {LZMA,BZ2,_Zlib}Decompressor (GH-148396) (#148479)
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 74be9e2 commit c3cf71c

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

591591
error:
592+
bzs->next_in = NULL;
592593
Py_XDECREF(result);
593594
return NULL;
594595
}

Modules/_lzmamodule.c

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

11141114
error:
1115+
lzs->next_in = NULL;
11151116
Py_XDECREF(result);
11161117
return NULL;
11171118
}

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)