btrfs: zstd-compressed files read back corrupt (regular + inline extents)
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- c
- Domain
- operating-systems
Research direction
Start in lib/zstd/zstd.c:zstd_decompress(), then trace its callers in fs/btrfs/compression.c:decompress_zstd() and fs/btrfs/inode.c:btrfs_read_extent_inline(). Validate regular and inline btrfs reads using payloads with concatenated zstd frames; done means the full input is consumed or the output is full without truncated or corrupt data.
Written by the indexing model from the issue text.
Description
Symptom
U-Boot reads zstd-compressed files from btrfs incorrectly. On our RK3576 images this surfaces when device-tree overlays / DTBs live on a btrfs subvolume with transparent zstd compression: the file reads back truncated/corrupt and fdt apply fails. Storing the files uncompressed (btrfs property set <file> compression none) is the only reliable workaround.
Affected read paths
Both btrfs decompression callers funnel into lib/zstd/zstd.c:zstd_decompress():
- Regular extents:
fs/btrfs/compression.c:decompress_zstd()(line 145) - Inline extents (small files):
fs/btrfs/inode.c:btrfs_read_extent_inline()(line 361) ->btrfs_decompress()
https://github.com/flipperdevices/u-boot/blob/b02abe709e76/lib/zstd/zstd.c#L34-L54
Suspected cause
In zstd_decompress(), the input length comes from zstd_find_frame_compressed_size(), which returns the size of only the first zstd frame, and zstd_decompress_dctx() then decompresses that single frame. When the compressed payload is more than one concatenated zstd frame, everything after the first is silently dropped and the output is truncated. The decompressor should iterate over frames until the whole input buffer is consumed (or the output is full).
Small files stored as compressed inline extents hit the same single-frame path and also read back wrong, so the fix needs to cover both callers.
Environment
- U-Boot @
b02abe709e76 - Platform: RK3576 (Flipper One), btrfs root with transparent zstd compression
Workaround
Keep DT overlays / DTBs uncompressed on btrfs (compression=none).
Bumping the bundled zstd (currently 1.5.2) is split out into #36.
- Dominant language
- C
- Stars
- 24
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No 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 flipperdevices/u-boot
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
flipperdevices/u-boot#33 · 1 comment ·
-
enhancement help wanted
Difficulty 4/5 3-5 days Newbie friendliness 35/100
flipperdevices/u-boot#40 · 7 comments ·
-
Bundle a newer zstd (currently 1.5.2)May be free again A pull request for this issue was closed without being merged. Openenhancement help wanted
Difficulty 3/5 1-2 days Newbie friendliness 64/100
flipperdevices/u-boot#36 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
flipperdevices/u-boot#34 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
flipperdevices/u-boot#32 · 2 comments ·
All issues in flipperdevices/u-boot
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
area:gates kind:gate-defect
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
InauguralSystems/EigenScript#2476 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
flipperdevices/flipperzero-firmware#4520 ·
Maintainers usually reply within 1 day
-
area/build-framework kind/enhancement priority/low
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
yugabyte/yugabyte-db#38826 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
meshcore-dev/MeshCore#3891 · 1 comment ·
Maintainers usually reply within 1 day