`ZSTD_getDictID_fromFrame` returns a skippable frame's magic variant as its dictionary ID
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 78/100
Research direction
Start in ZSTD_getDictID_fromFrame in lib/decompress/zstd_decompress.c, near line 1643, and compare it with the documented return value in lib/zstd.h around lines 1061-1071. Build the reproducer from the issue against lib/libzstd.a to confirm it prints 5 for the skippable frame. Done when the function returns 0 for skippable frames, ZSTD_getFrameHeader still reports the variant in dictID, and the existing test suite passes.
Written by the indexing model from the issue text.
Description
Describe the bug
Since v1.5.7, ZSTD_getDictID_fromFrame returns the magic variant (0-15) of a skippable frame as if it were a dictionary ID. zstd.h (L1061-L1071) documents a return of 0 when "This is not a Zstandard frame", and a skippable frame needs no dictionary.
Cause: commit a2ff6ea78 made ZSTD_getFrameHeader report the magic variant in dictID for skippable frames, which is documented on ZSTD_FrameHeader. ZSTD_getDictID_fromFrame (L1643-L1649) returns that field without checking the frame type.
To Reproduce
A skippable frame with magic 0x184D2A55 (variant 5) and 3 bytes of user data: 55 2a 4d 18 03 00 00 00 61 62 63.
make -C lib libzstd.acc -Ilib poc.c lib/libzstd.a -o poc && ./poc- Output:
ZSTD_getDictID_fromFrame(skippable frame, variant 5) = 5
poc.c
#include <stdio.h>
#include "zstd.h"
static const unsigned char frame[] = { 0x55, 0x2A, 0x4D, 0x18, 3, 0, 0, 0, 'a', 'b', 'c' };
int main(void)
{
unsigned id = ZSTD_getDictID_fromFrame(frame, sizeof frame);
printf("ZSTD_getDictID_fromFrame(skippable frame, variant 5) = %u\n", id);
return 0;
}
Expected behavior
ZSTD_getDictID_fromFrame returns 0 for a skippable frame, as v1.5.6 and earlier do.
Desktop:
- OS: Ubuntu 24.04.4 LTS
- Version: dev 49cf51799 and v1.5.7 return 5
- Compiler: gcc 13.3.0
- Flags: default
lib/Makefileflags, PoC built with-O2 - Other relevant hardware specs: x86_64
- Build system: Makefile
Additional context
Suggested fix: return 0 for skippable frames in ZSTD_getDictID_fromFrame and keep the variant in ZSTD_getFrameHeader, as documented. With it the PoC prints 0, and tests pass.
--- a/lib/decompress/zstd_decompress.c
+++ b/lib/decompress/zstd_decompress.c
@@ -1645,6 +1645,7 @@ unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize)
ZSTD_FrameHeader zfp = { 0, 0, 0, ZSTD_frame, 0, 0, 0, 0, 0 };
size_t const hError = ZSTD_getFrameHeader(&zfp, src, srcSize);
if (ZSTD_isError(hError)) return 0;
+ if (zfp.frameType == ZSTD_skippableFrame) return 0;
return zfp.dictID;
}
Found by genproof.com Formal Verification Agent. Reviewed and approved by a human.
- Dominant language
- C
- Stars
- 28.1k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from facebook/zstd
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
ZSTD_decompressStream accepts a Compressed_Block with Block_Size 0 that ZSTD_decompress rejectsPossibly taken @Artyx71 claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
One-shot decoding refuses some skippable framesPossibly taken @ceedot-rock claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
cover.c does not build on OpenHarmony: qsort_r is exported but not declared (musl)Possibly taken @bfs2021 claimed this 14 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
openziti/ziti-sdk-c#1254 ·
Maintainers usually reply within 1 day
-
http_fetch tests: the two no-child rows fail, not skip, where a task's children file does not existPossibly taken A pull request linked to this issue is open or already merged. Openarea:http kind:gate-defect
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
InauguralSystems/EigenScript#2397 ·
Maintainers usually reply within 1 day
-
Add SECURITY.mdOpenenhancement
Difficulty 1/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
modem: ppp: CMUX DLCI receive buffer overruns on large downlink packetsPossibly taken @pedrohqr claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
zephyrproject-rtos/zephyr#126195 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
ly05010419/MacNativeGames#2271 ·
Maintainers usually reply within 1 day