@@ -722,6 +722,67 @@ static int basicUnitTests(U32 seed, double compressibility, int bigTests)
722
722
}
723
723
DISPLAYLEVEL (3 , "OK \n" );
724
724
725
+ DISPLAYLEVEL (3 , "test%3i : maxBlockSize = 2KB : " , testNb ++ );
726
+ {
727
+ ZSTD_DCtx * dctx = ZSTD_createDCtx ();
728
+ size_t singlePassSize , streamingSize , streaming2KSize ;
729
+
730
+ {
731
+ ZSTD_CCtx * cctx = ZSTD_createCCtx ();
732
+ CHECK_Z (ZSTD_CCtx_setParameter (cctx , ZSTD_c_checksumFlag , 1 ));
733
+ CHECK_Z (ZSTD_CCtx_setParameter (cctx , ZSTD_c_windowLog , 18 ));
734
+ CHECK_Z (ZSTD_CCtx_setParameter (cctx , ZSTD_c_contentSizeFlag , 0 ));
735
+ CHECK_Z (ZSTD_CCtx_setParameter (cctx , ZSTD_c_maxBlockSize , 2048 ));
736
+ cSize = ZSTD_compress2 (cctx , compressedBuffer , compressedBufferSize , CNBuffer , CNBufferSize );
737
+ CHECK_Z (cSize );
738
+ ZSTD_freeCCtx (cctx );
739
+ }
740
+
741
+ CHECK_Z (ZSTD_decompressDCtx (dctx , decodedBuffer , CNBufferSize , compressedBuffer , cSize ));
742
+ singlePassSize = ZSTD_sizeof_DCtx (dctx );
743
+ CHECK_Z (singlePassSize );
744
+
745
+ inBuff .src = compressedBuffer ;
746
+ inBuff .size = cSize ;
747
+
748
+ outBuff .dst = decodedBuffer ;
749
+ outBuff .size = decodedBufferSize ;
750
+
751
+ CHECK_Z (ZSTD_DCtx_setParameter (dctx , ZSTD_d_maxBlockSize , 2048 ));
752
+ inBuff .pos = 0 ;
753
+ outBuff .pos = 0 ;
754
+ {
755
+ size_t const r = ZSTD_decompressStream (dctx , & outBuff , & inBuff );
756
+ CHECK_Z (r );
757
+ CHECK (r != 0 , "Entire frame must be decompressed" );
758
+ }
759
+ streaming2KSize = ZSTD_sizeof_DCtx (dctx );
760
+ CHECK_Z (streaming2KSize );
761
+
762
+ CHECK_Z (ZSTD_DCtx_reset (dctx , ZSTD_reset_session_and_parameters ));
763
+ inBuff .pos = 0 ;
764
+ outBuff .pos = 0 ;
765
+ {
766
+ size_t const r = ZSTD_decompressStream (dctx , & outBuff , & inBuff );
767
+ CHECK_Z (r );
768
+ CHECK (r != 0 , "Entire frame must be decompressed" );
769
+ }
770
+ streamingSize = ZSTD_sizeof_DCtx (dctx );
771
+ CHECK_Z (streamingSize );
772
+
773
+ CHECK_Z (ZSTD_DCtx_setParameter (dctx , ZSTD_d_maxBlockSize , 1024 ));
774
+ inBuff .pos = 0 ;
775
+ outBuff .pos = 0 ;
776
+ CHECK (!ZSTD_isError (ZSTD_decompressStream (dctx , & outBuff , & inBuff )), "decompression must fail" );
777
+
778
+ CHECK (streamingSize < singlePassSize + (1 << 18 ) + 3 * ZSTD_BLOCKSIZE_MAX , "Streaming doesn't use the right amount of memory" );
779
+ CHECK (streamingSize != streaming2KSize + 3 * (ZSTD_BLOCKSIZE_MAX - 2048 ), "ZSTD_d_blockSizeMax didn't save the right amount of memory" );
780
+ DISPLAYLEVEL (3 , "| %zu | %zu | %zu | " , singlePassSize , streaming2KSize , streamingSize );
781
+
782
+ ZSTD_freeDCtx (dctx );
783
+ }
784
+ DISPLAYLEVEL (3 , "OK \n" );
785
+
725
786
/* Decompression with ZSTD_d_stableOutBuffer */
726
787
cSize = ZSTD_compress (compressedBuffer , compressedBufferSize , CNBuffer , CNBufferSize , 1 );
727
788
CHECK_Z (cSize );
@@ -2845,6 +2906,13 @@ static int fuzzerTests_newAPI(U32 seed, int nbTests, int startTest,
2845
2906
if (FUZ_rand (& lseed ) & 1 ) CHECK_Z ( setCCtxParameter (zc , cctxParams , ZSTD_c_forceMaxWindow , FUZ_rand (& lseed ) & 1 , opaqueAPI ) );
2846
2907
if (FUZ_rand (& lseed ) & 1 ) CHECK_Z ( setCCtxParameter (zc , cctxParams , ZSTD_c_deterministicRefPrefix , FUZ_rand (& lseed ) & 1 , opaqueAPI ) );
2847
2908
2909
+ /* Set max block size parameters */
2910
+ if (FUZ_rand (& lseed ) & 1 ) {
2911
+ int maxBlockSize = (int )(FUZ_rand (& lseed ) % ZSTD_BLOCKSIZE_MAX );
2912
+ maxBlockSize = MAX (1024 , maxBlockSize );
2913
+ CHECK_Z ( setCCtxParameter (zc , cctxParams , ZSTD_c_maxBlockSize , maxBlockSize , opaqueAPI ) );
2914
+ }
2915
+
2848
2916
/* Apply parameters */
2849
2917
if (opaqueAPI ) {
2850
2918
DISPLAYLEVEL (5 , "t%u: applying CCtxParams \n" , testNb );
@@ -2976,6 +3044,13 @@ static int fuzzerTests_newAPI(U32 seed, int nbTests, int startTest,
2976
3044
if (FUZ_rand (& lseed ) & 1 ) {
2977
3045
CHECK_Z (ZSTD_DCtx_setParameter (zd , ZSTD_d_disableHuffmanAssembly , FUZ_rand (& lseed ) & 1 ));
2978
3046
}
3047
+ if (FUZ_rand (& lseed ) & 1 ) {
3048
+ int maxBlockSize ;
3049
+ CHECK_Z (ZSTD_CCtx_getParameter (zc , ZSTD_c_maxBlockSize , & maxBlockSize ));
3050
+ CHECK_Z (ZSTD_DCtx_setParameter (zd , ZSTD_d_maxBlockSize , maxBlockSize ));
3051
+ } else {
3052
+ CHECK_Z (ZSTD_DCtx_setParameter (zd , ZSTD_d_maxBlockSize , 0 ));
3053
+ }
2979
3054
{ size_t decompressionResult = 1 ;
2980
3055
ZSTD_inBuffer inBuff = { cBuffer , cSize , 0 };
2981
3056
ZSTD_outBuffer outBuff = { dstBuffer , dstBufferSize , 0 };
0 commit comments