23
23
*/
24
24
25
25
/* deflate.c -- compress data using the deflation algorithm
26
- * Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
26
+ * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
27
27
* For conditions of distribution and use, see copyright notice in zlib.h
28
28
*/
29
29
76
76
#include "deflate.h"
77
77
78
78
const char deflate_copyright [] =
79
- " deflate 1.3 Copyright 1995-2023 Jean-loup Gailly and Mark Adler " ;
79
+ " deflate 1.3.1 Copyright 1995-2024 Jean-loup Gailly and Mark Adler " ;
80
80
/*
81
81
If you use the zlib library in a product, an acknowledgment is welcome
82
82
in the documentation of your product. If for some reason you cannot
@@ -517,7 +517,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
517
517
* symbols from which it is being constructed.
518
518
*/
519
519
520
- s -> pending_buf = (uchf * ) ZALLOC (strm , s -> lit_bufsize , 4 );
520
+ s -> pending_buf = (uchf * ) ZALLOC (strm , s -> lit_bufsize , LIT_BUFS );
521
521
s -> pending_buf_size = (ulg )s -> lit_bufsize * 4 ;
522
522
523
523
if (s -> window == Z_NULL || s -> prev == Z_NULL || s -> head == Z_NULL ||
@@ -527,8 +527,14 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
527
527
deflateEnd (strm );
528
528
return Z_MEM_ERROR ;
529
529
}
530
+ #ifdef LIT_MEM
531
+ s -> d_buf = (ushf * )(s -> pending_buf + (s -> lit_bufsize << 1 ));
532
+ s -> l_buf = s -> pending_buf + (s -> lit_bufsize << 2 );
533
+ s -> sym_end = s -> lit_bufsize - 1 ;
534
+ #else
530
535
s -> sym_buf = s -> pending_buf + s -> lit_bufsize ;
531
536
s -> sym_end = (s -> lit_bufsize - 1 ) * 3 ;
537
+ #endif
532
538
/* We avoid equality with lit_bufsize*3 because of wraparound at 64K
533
539
* on 16 bit machines and because stored blocks are restricted to
534
540
* 64K-1 bytes.
@@ -744,9 +750,15 @@ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {
744
750
745
751
if (deflateStateCheck (strm )) return Z_STREAM_ERROR ;
746
752
s = strm -> state ;
753
+ #ifdef LIT_MEM
754
+ if (bits < 0 || bits > 16 ||
755
+ (uchf * )s -> d_buf < s -> pending_out + ((Buf_size + 7 ) >> 3 ))
756
+ return Z_BUF_ERROR ;
757
+ #else
747
758
if (bits < 0 || bits > 16 ||
748
759
s -> sym_buf < s -> pending_out + ((Buf_size + 7 ) >> 3 ))
749
760
return Z_BUF_ERROR ;
761
+ #endif
750
762
do {
751
763
put = Buf_size - s -> bi_valid ;
752
764
if (put > bits )
@@ -1318,7 +1330,7 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
1318
1330
ds -> window = (Bytef * ) ZALLOC (dest , ds -> w_size , 2 * sizeof (Byte ));
1319
1331
ds -> prev = (Posf * ) ZALLOC (dest , ds -> w_size , sizeof (Pos ));
1320
1332
ds -> head = (Posf * ) ZALLOC (dest , ds -> hash_size , sizeof (Pos ));
1321
- ds -> pending_buf = (uchf * ) ZALLOC (dest , ds -> lit_bufsize , 4 );
1333
+ ds -> pending_buf = (uchf * ) ZALLOC (dest , ds -> lit_bufsize , LIT_BUFS );
1322
1334
1323
1335
if (ds -> window == Z_NULL || ds -> prev == Z_NULL || ds -> head == Z_NULL ||
1324
1336
ds -> pending_buf == Z_NULL ) {
@@ -1329,10 +1341,15 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
1329
1341
zmemcpy (ds -> window , ss -> window , ds -> w_size * 2 * sizeof (Byte ));
1330
1342
zmemcpy ((voidpf )ds -> prev , (voidpf )ss -> prev , ds -> w_size * sizeof (Pos ));
1331
1343
zmemcpy ((voidpf )ds -> head , (voidpf )ss -> head , ds -> hash_size * sizeof (Pos ));
1332
- zmemcpy (ds -> pending_buf , ss -> pending_buf , ( uInt ) ds -> pending_buf_size );
1344
+ zmemcpy (ds -> pending_buf , ss -> pending_buf , ds -> lit_bufsize * LIT_BUFS );
1333
1345
1334
1346
ds -> pending_out = ds -> pending_buf + (ss -> pending_out - ss -> pending_buf );
1347
+ #ifdef LIT_MEM
1348
+ ds -> d_buf = (ushf * )(ds -> pending_buf + (ds -> lit_bufsize << 1 ));
1349
+ ds -> l_buf = ds -> pending_buf + (ds -> lit_bufsize << 2 );
1350
+ #else
1335
1351
ds -> sym_buf = ds -> pending_buf + ds -> lit_bufsize ;
1352
+ #endif
1336
1353
1337
1354
ds -> l_desc .dyn_tree = ds -> dyn_ltree ;
1338
1355
ds -> d_desc .dyn_tree = ds -> dyn_dtree ;
@@ -1563,13 +1580,21 @@ local uInt longest_match(deflate_state *s, IPos cur_match) {
1563
1580
*/
1564
1581
local void check_match (deflate_state * s , IPos start , IPos match , int length ) {
1565
1582
/* check that the match is indeed a match */
1566
- if (zmemcmp (s -> window + match ,
1567
- s -> window + start , length ) != EQUAL ) {
1568
- fprintf (stderr , " start %u, match %u, length %d\n" ,
1569
- start , match , length );
1583
+ Bytef * back = s -> window + (int )match , * here = s -> window + start ;
1584
+ IPos len = length ;
1585
+ if (match == (IPos )- 1 ) {
1586
+ /* match starts one byte before the current window -- just compare the
1587
+ subsequent length-1 bytes */
1588
+ back ++ ;
1589
+ here ++ ;
1590
+ len -- ;
1591
+ }
1592
+ if (zmemcmp (back , here , len ) != EQUAL ) {
1593
+ fprintf (stderr , " start %u, match %d, length %d\n" ,
1594
+ start , (int )match , length );
1570
1595
do {
1571
- fprintf (stderr , "%c%c " , s -> window [ match ++ ], s -> window [ start ++ ] );
1572
- } while (-- length != 0 );
1596
+ fprintf (stderr , "(%02x %02x) " , * back ++ , * here ++ );
1597
+ } while (-- len != 0 );
1573
1598
z_error ("invalid match" );
1574
1599
}
1575
1600
if (z_verbose > 1 ) {
1 commit comments
openjdk-notifier[bot] commentedon Jan 31, 2024
Review
Issues