btrfs: zstd-compressed files read back corrupt (regular + inline extents)

Open
#35 1 comment 0 reactions 0 assignees View on GitHub

@Lachytonner is already working on this.

Since Aug 3, 2026.

  • #39 by @Lachytonner — open

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

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

bug help wanted

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

  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 flipperdevices/u-boot

All issues in flipperdevices/u-boot

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.