Commit 5c44459
committed
Fix a bug that can crash deflate on some input when using Z_FIXED.
This bug was reported by Danilo Ramos of Eideticom, Inc. It has
lain in wait 13 years before being found! The bug was introduced
in zlib 1.2.2.2, with the addition of the Z_FIXED option. That
option forces the use of fixed Huffman codes. For rare inputs with
a large number of distant matches, the pending buffer into which
the compressed data is written can overwrite the distance symbol
table which it overlays. That results in corrupted output due to
invalid distances, and can result in out-of-bound accesses,
crashing the application.
The fix here combines the distance buffer and literal/length
buffers into a single symbol buffer. Now three bytes of pending
buffer space are opened up for each literal or length/distance
pair consumed, instead of the previous two bytes. This assures
that the pending buffer cannot overwrite the symbol table, since
the maximum fixed code compressed length/distance is 31 bits, and
since there are four bytes of pending space for every three bytes
of symbol space.1 parent e99813d commit 5c44459
3 files changed
+79
-70
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | 258 | | |
264 | 259 | | |
265 | 260 | | |
| |||
329 | 324 | | |
330 | 325 | | |
331 | 326 | | |
332 | | - | |
333 | | - | |
334 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
335 | 368 | | |
336 | 369 | | |
337 | 370 | | |
| |||
340 | 373 | | |
341 | 374 | | |
342 | 375 | | |
343 | | - | |
344 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
345 | 382 | | |
346 | 383 | | |
347 | 384 | | |
| |||
552 | 589 | | |
553 | 590 | | |
554 | 591 | | |
555 | | - | |
| 592 | + | |
556 | 593 | | |
557 | 594 | | |
558 | 595 | | |
| |||
1113 | 1150 | | |
1114 | 1151 | | |
1115 | 1152 | | |
1116 | | - | |
1117 | 1153 | | |
1118 | 1154 | | |
1119 | 1155 | | |
| |||
1133 | 1169 | | |
1134 | 1170 | | |
1135 | 1171 | | |
1136 | | - | |
1137 | | - | |
| 1172 | + | |
1138 | 1173 | | |
1139 | 1174 | | |
1140 | 1175 | | |
| |||
1148 | 1183 | | |
1149 | 1184 | | |
1150 | 1185 | | |
1151 | | - | |
1152 | | - | |
| 1186 | + | |
1153 | 1187 | | |
1154 | 1188 | | |
1155 | 1189 | | |
| |||
1925 | 1959 | | |
1926 | 1960 | | |
1927 | 1961 | | |
1928 | | - | |
| 1962 | + | |
1929 | 1963 | | |
1930 | 1964 | | |
1931 | 1965 | | |
| |||
2056 | 2090 | | |
2057 | 2091 | | |
2058 | 2092 | | |
2059 | | - | |
| 2093 | + | |
2060 | 2094 | | |
2061 | 2095 | | |
2062 | 2096 | | |
| |||
2131 | 2165 | | |
2132 | 2166 | | |
2133 | 2167 | | |
2134 | | - | |
| 2168 | + | |
2135 | 2169 | | |
2136 | 2170 | | |
2137 | 2171 | | |
| |||
2170 | 2204 | | |
2171 | 2205 | | |
2172 | 2206 | | |
2173 | | - | |
| 2207 | + | |
2174 | 2208 | | |
2175 | 2209 | | |
2176 | 2210 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
| 220 | + | |
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 242 | + | |
| 243 | + | |
249 | 244 | | |
250 | 245 | | |
251 | 246 | | |
| |||
325 | 320 | | |
326 | 321 | | |
327 | 322 | | |
328 | | - | |
329 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
330 | 326 | | |
331 | | - | |
| 327 | + | |
332 | 328 | | |
333 | 329 | | |
334 | 330 | | |
335 | 331 | | |
336 | | - | |
337 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
338 | 335 | | |
339 | 336 | | |
340 | 337 | | |
341 | | - | |
| 338 | + | |
342 | 339 | | |
343 | 340 | | |
344 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
419 | | - | |
| 419 | + | |
420 | 420 | | |
421 | 421 | | |
422 | 422 | | |
| |||
948 | 948 | | |
949 | 949 | | |
950 | 950 | | |
951 | | - | |
| 951 | + | |
952 | 952 | | |
953 | 953 | | |
954 | 954 | | |
| |||
1017 | 1017 | | |
1018 | 1018 | | |
1019 | 1019 | | |
1020 | | - | |
1021 | | - | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
1022 | 1023 | | |
1023 | 1024 | | |
1024 | 1025 | | |
| |||
1033 | 1034 | | |
1034 | 1035 | | |
1035 | 1036 | | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
1054 | | - | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
1059 | | - | |
| 1037 | + | |
1060 | 1038 | | |
1061 | 1039 | | |
1062 | 1040 | | |
| |||
1069 | 1047 | | |
1070 | 1048 | | |
1071 | 1049 | | |
1072 | | - | |
| 1050 | + | |
1073 | 1051 | | |
1074 | 1052 | | |
1075 | 1053 | | |
1076 | | - | |
1077 | | - | |
1078 | | - | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
1079 | 1058 | | |
1080 | 1059 | | |
1081 | 1060 | | |
| |||
1100 | 1079 | | |
1101 | 1080 | | |
1102 | 1081 | | |
1103 | | - | |
1104 | | - | |
1105 | | - | |
| 1082 | + | |
| 1083 | + | |
1106 | 1084 | | |
1107 | | - | |
| 1085 | + | |
1108 | 1086 | | |
1109 | 1087 | | |
1110 | 1088 | | |
| |||
0 commit comments