Skip to content

Commit efc9ae3

Browse files
authored
Merge pull request #3455 from facebook/fix3454
Provide more accurate error codes for busy-loop scenarios
2 parents 321490c + db18a62 commit efc9ae3

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

lib/common/error_private.c

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const char* ERR_getErrorString(ERR_enum code)
4747
case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
4848
case PREFIX(srcSize_wrong): return "Src size is incorrect";
4949
case PREFIX(dstBuffer_null): return "Operation on NULL destination buffer";
50+
case PREFIX(noForwardProgress_destFull): return "Operation made no progress over multiple calls, due to output buffer being full";
51+
case PREFIX(noForwardProgress_inputEmpty): return "Operation made no progress over multiple calls, due to input being empty";
5052
/* following error codes are not stable and may be removed or changed in a future version */
5153
case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
5254
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";

lib/decompress/zstd_decompress.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2238,7 +2238,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
22382238
int const isSkipFrame = ZSTD_isSkipFrame(zds);
22392239
size_t loadedSize;
22402240
/* At this point we shouldn't be decompressing a block that we can stream. */
2241-
assert(neededInSize == ZSTD_nextSrcSizeToDecompressWithInputSize(zds, iend - ip));
2241+
assert(neededInSize == ZSTD_nextSrcSizeToDecompressWithInputSize(zds, (size_t)(iend - ip)));
22422242
if (isSkipFrame) {
22432243
loadedSize = MIN(toLoad, (size_t)(iend-ip));
22442244
} else {
@@ -2298,8 +2298,8 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
22982298
if ((ip==istart) && (op==ostart)) { /* no forward progress */
22992299
zds->noForwardProgress ++;
23002300
if (zds->noForwardProgress >= ZSTD_NO_FORWARD_PROGRESS_MAX) {
2301-
RETURN_ERROR_IF(op==oend, dstSize_tooSmall, "");
2302-
RETURN_ERROR_IF(ip==iend, srcSize_wrong, "");
2301+
RETURN_ERROR_IF(op==oend, noForwardProgress_destFull, "");
2302+
RETURN_ERROR_IF(ip==iend, noForwardProgress_inputEmpty, "");
23032303
assert(0);
23042304
}
23052305
} else {

lib/zstd_errors.h

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ typedef enum {
8888
ZSTD_error_dstSize_tooSmall = 70,
8989
ZSTD_error_srcSize_wrong = 72,
9090
ZSTD_error_dstBuffer_null = 74,
91+
ZSTD_error_noForwardProgress_destFull = 80,
92+
ZSTD_error_noForwardProgress_inputEmpty = 82,
9193
/* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
9294
ZSTD_error_frameIndex_tooLarge = 100,
9395
ZSTD_error_seekableIO = 102,

0 commit comments

Comments
 (0)