fix(ingest): strip NUL bytes from EXIF/IPTC text before photo.create #91

Merged
spark merged 2 commits from fix/BIT-31182-null-byte-sanitize into main 2026-10-21 23:13:49 +01:00
Owner

Fixes BIT-31182.

Root cause: prisma.photo.create() failed with invalid byte sequence for encoding "UTF8": 0x00 (Postgres 22021). EXIF/IPTC readers only trim a trailing NUL pad (exif.ts str()) or none at all (embedded.ts text()), so a camera string with an embedded 0x00 byte reached the insert.

Fix: apps/api/src/lib/sanitize.ts adds stripNulBytes, a small recursive sanitizer (strings/arrays/plain objects; leaves Date and other instances untouched) applied to the photo.create() data in apps/api/src/ingest/service.ts, covering the flat camera fields and the nested exif/embeddedIptc JSON blobs in one pass.

Tests: apps/api/src/lib/sanitize.test.ts (unit, 3 cases: mid-string NUL removal, nested object/array recursion matching the real data shape, Date passthrough). Full src/lib + src/ingest suite green locally against photoreport_test.

Single occurrence (2026-10-15), no duplicates since.

Fixes BIT-31182. **Root cause:** `prisma.photo.create()` failed with `invalid byte sequence for encoding "UTF8": 0x00` (Postgres 22021). EXIF/IPTC readers only trim a trailing NUL pad (`exif.ts` `str()`) or none at all (`embedded.ts` `text()`), so a camera string with an embedded 0x00 byte reached the insert. **Fix:** `apps/api/src/lib/sanitize.ts` adds `stripNulBytes`, a small recursive sanitizer (strings/arrays/plain objects; leaves `Date` and other instances untouched) applied to the `photo.create()` data in `apps/api/src/ingest/service.ts`, covering the flat camera fields and the nested `exif`/`embeddedIptc` JSON blobs in one pass. **Tests:** `apps/api/src/lib/sanitize.test.ts` (unit, 3 cases: mid-string NUL removal, nested object/array recursion matching the real data shape, Date passthrough). Full `src/lib` + `src/ingest` suite green locally against `photoreport_test`. Single occurrence (2026-10-15), no duplicates since.
spark added 1 commit 2026-10-21 18:15:53 +01:00
fix(ingest): strip NUL bytes from EXIF/IPTC text before photo.create
ci / rust (pull_request) Successful in 11m19s
ci / typescript (pull_request) Failing after 13m56s
16e3dd2c53
EXIF/IPTC readers only trimmed a trailing NUL pad (exif.ts str()) or none at
all (embedded.ts text()), so a camera string with an embedded 0x00 byte
reached prisma.photo.create() and Postgres rejected the whole insert with
"invalid byte sequence for encoding \"UTF8\": 0x00" (22021), failing the photo
permanently. Run the create payload through a small recursive sanitizer
that strips NUL bytes from every string, nested object and array (so
exif/embeddedIptc JSON blobs are covered too) while leaving Date and other
non-plain values untouched.

BIT-31182

Paperclip-Agent: Miguel Teixeira (urlKey miguel-teixeira; id 0f722e1a-bc3e-4381-8d98-76fa3c7aea10)
Paperclip-Issue: BIT-31182
Paperclip-Run: 052a774e-42b2-4c28-8734-ac4cc5714c47
Member

@cto — Gitea autopilot needs a CTO decision on BitReport.pt/photoreport#91: CI is red on the PR head.

  • Head: 16e3dd2c536f
  • Detail: failed contexts: ci / typescript (pull_request)
  • The bot did not approve or schedule a merge for this head.
  • Fix the branch, approve as CTO, or close the PR. The bot re-checks on the next run.
@cto — Gitea autopilot needs a CTO decision on BitReport.pt/photoreport#91: CI is red on the PR head. - Head: `16e3dd2c536f` - Detail: failed contexts: ci / typescript (pull_request) - The bot did **not** approve or schedule a merge for this head. - Fix the branch, approve as CTO, or close the PR. The bot re-checks on the next run. <!-- gitea-autopilot-escalation kind=ci_failure sha=16e3dd2c536f -->
spark added 1 commit 2026-10-21 22:54:19 +01:00
Merge branch 'main' into fix/BIT-31182-null-byte-sanitize
ci / rust (pull_request) Successful in 16m40s
ci / typescript (pull_request) Successful in 18m4s
5ecfb84f20
spark merged commit df5894c990 into main 2026-10-21 23:13:49 +01:00
Sign in to join this conversation.