Skip to content

Commit ddd0730

Browse files
LTSCommerceclaude
andcommitted
ftp-camera: make the ARW completeness check definitive, not pattern-matched
The first cut of the ARW branch matched exiftool output against 'truncat|corrupt|bad offset|bad format|missing.*end|premature'. Two of those terms are dangerous: "bad format" and "corrupt" appear for benign maker-note quirks in perfectly good Sony files. On a network where every transfer is already struggling, rejecting every ARW would have been its own outage — and a false "truncated" verdict is worse than useless because it looks like evidence. Replaced with a definitive test that runs first. ARW is TIFF: the IFDs record where each data strip begins (StripOffsets) and how long it is (StripByteCounts). If any strip is declared to end beyond the actual end of file, bytes are provably missing. No judgement and no pattern matching, and it cannot false-positive on a valid file, because a valid file's strips are all inside it. The exiftool-wording check remains only as a fallback, narrowed to unambiguous truncation terms. Anything short of an explicit truncation report now returns UNVERIFIED (2) rather than TRUNCATED (1), so an ambiguous validator result never blocks a good RAW — it warns instead. Tested the overflow arithmetic against strips that fit, strips that run past EOF, and missing tags; all three classify correctly. The JPEG path (SOI/EOI) remains the exact one and is unchanged. Refs: CLAUDE/Plan/00066-ftp-camera-airbnb-wifi-and-hotspot-triage Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 2cbd580 commit ddd0730

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

files/home/.local/bin/ftp-camera

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,46 @@ verify_file_complete() {
583583
# NOT a completeness signal. That is exactly how fragments got
584584
# filed under the right date in the first place.
585585
command -v exiftool > /dev/null || return 2
586+
587+
# DEFINITIVE test first, where the tags allow it. ARW is TIFF: the
588+
# IFDs record where each data strip starts and how long it is. If
589+
# any strip is declared to end beyond the actual end of file, bytes
590+
# are provably missing. No judgement, no pattern matching — and it
591+
# cannot false-positive on a valid file, because a valid file's
592+
# strips are all inside it.
593+
local sizes
594+
if sizes=$(exiftool -s3 -a -FileSize# -StripOffsets -StripByteCounts "$file" 2>&1); then
595+
if printf '%s\n' "$sizes" | awk '
596+
NR == 1 { fsize = $1 + 0; next }
597+
# Offsets and byte-counts arrive as parallel space- or
598+
# comma-separated lists; pair them up positionally.
599+
{ gsub(/,/, " "); n = split($0, a, " ")
600+
if (off_n == 0) { for (i = 1; i <= n; i++) off[i] = a[i] + 0; off_n = n }
601+
else { for (i = 1; i <= n; i++) len[i] = a[i] + 0; len_n = n }
602+
}
603+
END {
604+
if (fsize == 0 || off_n == 0 || len_n == 0) exit 1
605+
for (i = 1; i <= off_n && i <= len_n; i++)
606+
if (off[i] + len[i] > fsize) exit 0 # provably short
607+
exit 1
608+
}'; then
609+
return 1
610+
fi
611+
fi
612+
613+
# Fallback: exiftool's own structural validation. Deliberately
614+
# narrow — only unambiguous truncation wording counts. Broader
615+
# terms ("bad format", "corrupt") show up for benign maker-note
616+
# quirks in perfectly good Sony files, and rejecting every ARW on
617+
# this network would be its own outage. Anything short of an
618+
# explicit truncation report is reported as UNVERIFIED (2) rather
619+
# than assumed bad.
586620
local validation
587621
if ! validation=$(exiftool -validate -warning -error -a -s3 "$file" 2>&1); then
588-
return 1
622+
return 2
589623
fi
590624
if printf '%s' "$validation" \
591-
| grep -qiE 'truncat|corrupt|bad offset|bad format|missing.*end|premature'; then
625+
| grep -qiE 'truncat|premature|unexpected end|missing .*end of'; then
592626
return 1
593627
fi
594628
return 0

0 commit comments

Comments
 (0)