Skip to content

Legacy v0.5 streaming decompression produces different bytes than one-shot API #4553

@simonresch

Description

@simonresch

Describe the bug
A legacy v0.5 frame (magic 0xFD2FB525) decodes to different outputs depending on whether it is processed via ZSTD_decompress or ZSTD_decompressStream. Both APIs report success and produce the same output length, but the contents differ.

To Reproduce

  • Place the attached reproducer legacy_stream_mismatch.c in tests/reproducers
  • Add the following to build/cmake/tests/CMakeLists.txt
add_executable(legacy_stream_mismatch ${TESTS_DIR}/reproducers/legacy_stream_mismatch.c)
target_link_libraries(legacy_stream_mismatch libzstd_static)

Build and run:

cmake -S . -B build/repro -DZSTD_BUILD_TESTS=ON -DZSTD_LEGACY_SUPPORT=5
cmake --build build/repro --config Release --target legacy_stream_mismatch
./build/repro/build/cmake/tests/legacy_stream_mismatch

Output:

Mismatch: one_shot_size=283 stream_size=283 first_diff=14 (one_shot=0x4e, stream=0x68)
one_shot text:
NNNNNNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNNNNhNNNNNhhhhhhhhhhhh
streamed text:
NNNNNNNNNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNNNNhhhhNNhhhhhhhhhhhh

Expected behavior
Decoded bytes should be the same using both APIs.

Desktop (please complete the following information):

  • OS: Linux
  • Version: current working tree (1.5.8 at time of report)
  • Compiler: gcc & clang

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions