Skip to content

Commit d93382d

Browse files
committed
refactor: disable dcz encoding when dictionary loading fails
1 parent 229de91 commit d93382d

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

zstd.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,6 @@ php_zstd_output_handler_load_dict(php_zstd_context *ctx)
12981298
char *dict = PHP_ZSTD_G(output_compression_dict);
12991299

13001300
if (!dict || strlen(dict) <= 0) {
1301-
PHP_ZSTD_G(compression_coding) &= ~PHP_ZSTD_ENCODING_DCZ;
13021301
return NULL;
13031302
}
13041303

@@ -1308,7 +1307,6 @@ php_zstd_output_handler_load_dict(php_zstd_context *ctx)
13081307
NULL, context);
13091308
if (!stream) {
13101309
ZSTD_WARNING("could not open dictionary stream: %s", dict);
1311-
PHP_ZSTD_G(compression_coding) &= ~PHP_ZSTD_ENCODING_DCZ;
13121310
return NULL;
13131311
}
13141312

@@ -1322,7 +1320,6 @@ php_zstd_output_handler_load_dict(php_zstd_context *ctx)
13221320
php_stream_close(stream);
13231321

13241322
if (!data) {
1325-
PHP_ZSTD_G(compression_coding) &= ~PHP_ZSTD_ENCODING_DCZ;
13261323
return NULL;
13271324
}
13281325

@@ -1360,7 +1357,6 @@ php_zstd_output_handler_load_dict(php_zstd_context *ctx)
13601357
} else {
13611358
php_error_docref(NULL, E_WARNING,
13621359
"zstd: not found available-dictionary");
1363-
PHP_ZSTD_G(compression_coding) &= ~PHP_ZSTD_ENCODING_DCZ;
13641360
zend_string_release(data);
13651361
data = NULL;
13661362
}
@@ -1378,6 +1374,9 @@ static zend_result php_zstd_output_handler_context_start(php_zstd_context *ctx)
13781374
}
13791375

13801376
zend_string *dict = php_zstd_output_handler_load_dict(ctx);
1377+
if (dict == NULL) {
1378+
PHP_ZSTD_G(compression_coding) &= ~PHP_ZSTD_ENCODING_DCZ;
1379+
}
13811380
if (!PHP_ZSTD_G(compression_coding)) {
13821381
return FAILURE;
13831382
}

0 commit comments

Comments
 (0)