File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -399,10 +399,43 @@ ZEND_FUNCTION(zstd_uncompress_dict)
399399 RETURN_FALSE ;
400400 }
401401 } else {
402- zend_string_efree (output );
403- ZSTD_freeDDict (ddict );
404- ZSTD_WARNING ("can not decompress stream" );
405- RETURN_FALSE ;
402+ ZSTD_inBuffer in = { NULL , 0 , 0 };
403+ ZSTD_outBuffer out = { NULL , 0 , 0 };
404+ size_t chunk = ZSTD_DStreamOutSize ();
405+
406+ ZSTD_DCtx_reset (dctx , ZSTD_reset_session_only );
407+ ZSTD_DCtx_refDDict (dctx , ddict );
408+
409+ in .src = input ;
410+ in .size = input_len ;
411+ in .pos = 0 ;
412+
413+ out .dst = ZSTR_VAL (output );
414+ out .size = size ;
415+ out .pos = 0 ;
416+
417+ while (in .pos < in .size ) {
418+ if (out .pos == out .size ) {
419+ out .size += chunk ;
420+ output = zend_string_extend (output , out .size , 0 );
421+ out .dst = ZSTR_VAL (output );
422+ }
423+
424+ result = ZSTD_decompressStream (dctx , & out , & in );
425+ if (ZSTD_IS_ERROR (result )) {
426+ zend_string_efree (output );
427+ ZSTD_freeDCtx (dctx );
428+ ZSTD_freeDDict (ddict );
429+ ZSTD_WARNING ("%s" , ZSTD_getErrorName (result ));
430+ RETURN_FALSE ;
431+ }
432+
433+ if (result == 0 ) {
434+ break ;
435+ }
436+ }
437+
438+ result = out .pos ;
406439 }
407440
408441 ZSTD_freeDCtx (dctx );
You can’t perform that action at this time.
0 commit comments