Skip to content

build_manifest: UnicodeDecodeError on small non-UTF-8 blobs #16

Closed

Description

@neuromechanist

Symptom

`scripts/emit_manifest.py:232` calls `run(["git", ..., "cat-file", "blob", sha])` for any regular blob ≤ 512 bytes to detect unlocked-mode git-annex pointers. `run()` (`scripts/emit_manifest.py:97`) wraps `subprocess.check_output(..., text=True)`, which decodes the blob as UTF-8.

If a dataset commits a non-UTF-8 file smaller than 512 bytes (a binary calibration sidecar, a thumbnail, etc.), `build_manifest()` crashes with:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

The entire publish workflow then dies before any output is written.

Reproduction

Add a small binary file at the BIDS root and tag it:

printf '\xff\xfe\x00\x01binary' > junk.bin
git add junk.bin && git commit -m '.' && git tag v0.0.0
python3 scripts/emit_manifest.py --dataset-id nm099999 --version 0.0.0 \
  --repo-dir . --out-dir /tmp/out --no-verify-canary --doi '' --concept-doi ''

Discovered while authoring the binary-README test for PR #15 (epic nemarOrg/nemar-cli#618). The test fixture sidesteps the bug by padding payloads > 512 bytes; this issue tracks the real fix.

Proposed fix

The pointer-detection check only needs to compare the first ~50 bytes against the literal `/annex/objects/` pattern. Read the blob as bytes (omit `text=True`) and decode only the leading prefix with `errors="replace"` or `errors="ignore"`. Optionally skip the check entirely if the first byte isn't `/`.

Impact

  • Latent for now: most BIDS datasets don't have <512-byte binary files at submission time, so it hasn't been hit in production.
  • Will hit if anyone publishes a dataset with binary calibration files (common in MEG/EEG) ≤ 512 bytes.
  • Out of scope for PR feat(emit-manifest): schema 1.1 — embed README content inline #15 (schema 1.1 README inline) — that PR adds a workaround in its test fixture.

Activity

  1. added
    bug
    on May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions