Commit f897dbf
Patch by @tonghuaroot.
zipfile.ZipExtFile._read1() bounds the output of each decompress() call
for DEFLATE members by passing a max_length to zlib, but for bzip2, LZMA,
and Zstandard members it called decompress() with no bound. A whole
compressed chunk was therefore expanded into a single allocation before
the data[:self._left] clip ran, so a consumer that deliberately reads in
small chunks to limit memory (for example zf.open(name).read(8192)) was
silently unprotected for non-DEFLATE members. A small, spec-conformant
archive member declaring a large uncompressed size could drive multi-GB
peak memory.
_read1() now passes a per-call bound to the non-DEFLATE decompress()
(mirroring the DEFLATE branch) and drains the decompressor's internal
buffer across calls by checking needs_input before reading more
compressed input. zipfile's LZMADecompressor wrapper forwards max_length
and exposes needs_input so the bound also holds for LZMA members.
Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
1 parent 9cbd578 commit f897dbf
3 files changed
Lines changed: 79 additions & 5 deletions
File tree
- Lib
- test/test_zipfile
- zipfile
- Misc/NEWS.d/next/Security
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4874 | 4874 | | |
4875 | 4875 | | |
4876 | 4876 | | |
| 4877 | + | |
| 4878 | + | |
| 4879 | + | |
| 4880 | + | |
| 4881 | + | |
| 4882 | + | |
| 4883 | + | |
| 4884 | + | |
| 4885 | + | |
| 4886 | + | |
| 4887 | + | |
| 4888 | + | |
| 4889 | + | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
| 4898 | + | |
| 4899 | + | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
| 4904 | + | |
| 4905 | + | |
| 4906 | + | |
| 4907 | + | |
| 4908 | + | |
| 4909 | + | |
| 4910 | + | |
| 4911 | + | |
| 4912 | + | |
| 4913 | + | |
| 4914 | + | |
| 4915 | + | |
| 4916 | + | |
| 4917 | + | |
| 4918 | + | |
4877 | 4919 | | |
4878 | 4920 | | |
4879 | 4921 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
801 | 801 | | |
802 | 802 | | |
803 | 803 | | |
804 | | - | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
805 | 814 | | |
806 | 815 | | |
807 | 816 | | |
| |||
817 | 826 | | |
818 | 827 | | |
819 | 828 | | |
820 | | - | |
| 829 | + | |
821 | 830 | | |
822 | 831 | | |
823 | 832 | | |
| |||
884 | 893 | | |
885 | 894 | | |
886 | 895 | | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
887 | 903 | | |
888 | 904 | | |
889 | 905 | | |
| |||
1186 | 1202 | | |
1187 | 1203 | | |
1188 | 1204 | | |
1189 | | - | |
| 1205 | + | |
1190 | 1206 | | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
1191 | 1214 | | |
1192 | 1215 | | |
1193 | 1216 | | |
| |||
1200 | 1223 | | |
1201 | 1224 | | |
1202 | 1225 | | |
1203 | | - | |
1204 | | - | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
1205 | 1233 | | |
1206 | 1234 | | |
1207 | 1235 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments