`ZSTD_getDictID_fromFrame` returns a skippable frame's magic variant as its dictionary ID

Open Beginner friendly
#4,881 0 comments 0 reactions 0 assignees View on GitHub

@b84330808 is already working on this.

Since Nov 5, 2026.

  • #4894 by @b84330808 — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
data

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.

  1. make -C lib libzstd.a
  2. cc -Ilib poc.c lib/libzstd.a -o poc && ./poc
  3. 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/Makefile flags, 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from facebook/zstd

All issues in facebook/zstd

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.