Reads a stag CSV, orders the geotagged rows by their parsed timestamp (ISO and EXIF-colon forms sort together), and draws the trip on an OSM map: blue line with white halo, direction arrowhead per leg, red marker per stop, MM-DD HH:MM label per timestamped stop. Rows without a timestamp go last in CSV order; rows without coordinates are skipped. Reuses sgeo tile/zoom/marker code via shared fetch_tiles/draw_attribution helpers. Tests: 11/11 in tests/run_tests.sh (3 new trip cases + tests/check_trip.py). Docs: docs/trip-path.md.
sfile — super file
sfile is a file command that does detailed file header decoding.
Given a file, it identifies the format (by magic bytes, falling back to the
filename extension) and prints the header as a uniform table: field names,
offsets, sizes and values.
$ sfile photo.png
File: photo.png (15234 bytes)
Format: PNG image (.PNG) — task 564
Identified by: magic
Magic: 89 50 4e 47 0d 0a 1a 0a at offset 0
Header (big-endian):
offset size field value
0 8 signature 89 50 4e 47 0d 0a 1a 0a
8 4 ihdr_length 13
12 4 ihdr_type "IHDR"
16 4 width 800
20 4 height 600
24 1 bit_depth 8
25 1 color_type 2
...
Coverage
850 formats (the 849 that exist at fileformat.vpscoder.com — "860" is the
max task number; 11 numbers have no published page — plus WebP, added as
task 861, which has no published page). The format table is
derived from the C/C++ reference code for each format (see
tools/all_formats.cpp, 833 code blocks from 831 tasks) plus a curated
magic table and hand overrides for well-known container formats
(PNG, ZIP, WAV/AVI, GIF, BMP, tar, …).
| derivation | count | meaning |
|---|---|---|
readseq |
29 | fields + offsets from a parsed sequential read sequence (highest confidence) |
struct |
208 | struct fields in order, sizes from C types (char[N] NUL slots are a known risk — the test loop verifies) |
explicit |
2 | C++ class reading data[N] / data + N with named properties |
text |
245 | XML/JSON/text format — decoded by the text decoder (root element, version, first line) |
container |
49 | inherits a container's fixed header (ZIP local header, RIFF, ftyp, Ogg page, gzip, RAR 4.x, IFF FORM, PDF, TIFF, OLE/CFB, ar, MZ/DOS) |
override |
104 | hand-written, spec-derived layout — verified against real samples |
magic-only |
3 | magic known, no fixed field layout |
nocode |
10 | no C/C++ code on the task page, no layout derived |
nocode-text |
5 | no C/C++ code, but the format is text |
unknown |
194 | nothing derivable from the reference code — identified by magic/extension only, hex dump shown |
308 formats have a magic signature; 389 have a field layout. The 18 tasks
with no C/C++ code at all (108, 151, 172, 233, 300, 312, 345, 369, 398, 408,
532, 623, 671, 720, 741, 757, 793, 794) are nocode/nocode-text unless a
hand override exists for them (300 ICE and 398 MKA have overrides).
Geotagging
After the header table, sfile prints a Geotagging: section for the
formats where GPS location genuinely exists, decoding it from the
container's own metadata (never invented). Latitude/longitude are decimal
degrees (with the DMS form in parentheses), altitude is metres above (or
below) sea level, datum defaults to WGS-84 (EPSG:4326), and the timestamp
is normalised to ISO YYYY-MM-DD HH:MM:SS UTC.
| format | task(s) | source decoded |
|---|---|---|
| JPEG, TIFF, CR2, NEF, DNG | 331/332, 730, 109, 445, 144 | EXIF GPS IFD via IFD0 tag 0x8825 (EXIF 2.32: 0x0000 version, 0x0001/0x0002 lat ref/value, 0x0003/0x0004 lon, 0x0005/0x0006 alt ref/value, 0x0007 timestamp, 0x0012 datum, 0x001D datestamp; RATIONAL[3] DMS) |
| GeoTIFF | 257 | ModelTiepointTag 33922 / ModelTransformationTag 34264 + GeoKeyDirectoryTag 34735 (GeoKey 2048 = 4326 WGS 84) |
| PNG | 564 | eXIf chunk (raw TIFF) and XMP in iTXt keyword XML:com.adobe.xmp |
| WebP | 861 | EXIF and XMP chunks (WebP has no blog task; added as 861 — see tools/overrides.json) |
| HEIC / HEIF / AVIF | 286, 287, 48 | Exif item in meta via iinf/iloc; XMP as a mime item (item_type "mime", content type application/rdf+xml) |
| MP4 / MOV / M4V / F4V / M4A | 415, 412, 373, 207, 370 | moov/udta (c)xyz atom (ISO 6709 string; canonical QuickTime text layout [u16 size][u16 lang]text, bare strings also accepted), moov/udta/meta key com.apple.quicktime.location.ISO6709 (keys/ilst), XMP in udta/XMP_ and in a top-level uuid box (UUID BE7ACFCB-97A9-42E8-9C71-999491E3AFAC — the layout exiftool itself writes) |
| 3GP / 3G2 | 4, 3 | moov/udta loci box (3GPP TS 26.244: signed 16.16 fixed-point lon/lat/alt) |
| CR3 | 110 | GPS IFD in the CMT4 box inside moov/uuid (Canon); XMP via the CTBO table entry 1 |
| EXR | 199 | header attributes longitude / latitude / altitude (float32, degrees E/N, metres) |
| JP2 | 329 | XMP in the uuid box (UUID BE7ACFCB-97A9-42E8-9C71-999491E3AFAC) or an xml box |
| PSD | 575 | EXIF in image resource 1058 (0x0422), XMP in resource 1060 (0x0424) |
| MKV / WebM | 399, 805 | XMP attachment only (no native GPS field exists) |
| AVI / DIVX | 47, 140 | XMP in the _PMX chunk only (no native GPS field exists) |
Deliberately not decoded: raw .j2k codestreams (no metadata),
MKV free-text RECORDING_LOCATION / LOCATION tags and AVI RIFF INFO
chunks (free text, not coordinates — a test fixture proves they are not
reported as GPS), WAV iXML LOCATION, JPEG XL Exif boxes. XMP coordinates
are accepted in DMS (37,46,29.64N), decimal-minutes (37,46.494N),
and bare-decimal forms.
Implementation is a dedicated pass in src/geotag.c / src/geotag.h
(dispatched from main() by task number — the fixed-offset header table
cannot express variable-offset metadata). A library entry point
geotag_scan(path, task, out, max_results) is declared in geotag.h;
the printed field names (source:, gps_latitude:, gps_longitude:,
gps_altitude_m:, gps_datum:, gps_datetime_utc:, none found (searched...)) are the stable output contract — other tools parse them.
Tests: tests/geotag/make_geotag_tests.py builds 26 fixtures with known
values (lat 37.7749 N, lon 122.4194 W, alt 10 m; MP4 keys/ilst uses the
published worked example, alt 30 m) plus two negative fixtures, and
tests/geotag/run_geotag_tests.py asserts sfile round-trips them
(26 PASS). Fixtures were cross-checked against exiftool 13.50, which
independently reads the same values from every fixture it supports
(including the real-world layouts: QuickTime text-prefixed (c)xyz,
moov/udta/meta with an hdlr child, HEIC mime content-type, EXR magic
76 2F 31 01, CR3 CMT4). Real files written by exiftool (JPEG EXIF,
MP4 XMP uuid) and ffmpeg (MP4 loci box — ffmpeg writes location
metadata as loci, not (c)xyz) were also decoded and agree.
Testing
tests/run_tests.py runs sfile on every sample in samples/ (one real
sample file per format, collected from the task pages' download links or by
web search) and records PASS / PARTIAL / FAIL / NO SAMPLE in
tests/results.json. Latest run (Dec 2, 2026, after the geotagging
round; counts unchanged from the Nov 25 PARTIAL round except NO SAMPLE
104 -> 105 for the new WebP task):
| result | count | meaning |
|---|---|---|
| PASS | 650 | identified and header decoded |
| PARTIAL | 97 | identified, no fixed header layout exists (see below) |
| FAIL | 2 | the 2 unresolvable duplicates 312 (.INI) = 311 and 520 (.PBO) = 519 |
| NO SAMPLE | 105 | no real sample file found yet (of 854 tasks counted by the harness, which includes 4 task numbers with no published page: 202, 214, 292, 389, plus WebP task 861) |
The PARTIAL tail (97) — why no layout exists
All 136 partials were triaged one by one (verdicts in
tools/triage_partial_B*.json); 39 had a real fixed layout in their
reference code or a verifiable spec and were converted to PASS. The
remaining 97 have no fixed header layout to write honestly, grouped by
reason:
- text (46) — the format is text/source with no binary header at all
(Fortran/Fortran-77 sources, FASTA, Lua/Lisp, JavaScript, JSP, HTA/HTML,
kernel
.config, Xilinx.coe, ChordPro, GML, Godot INI-style, UTF-16LE.klc, …). These identify by extension and print nothing further. - variable-length (15) — the header is variable-length by design: ASN.1 DER (P12/PFX, CER), varints after a magic (BPS, TAK), BER lengths (MXF was the exception — its 4-byte BER long-form is fixed enough to decode), NBT tags, MPCK packets, tokenized Paradox saves, ASCII text headers with variable-length lines (PAM/PBM/PFM), zlib streams.
- streaming (9) — frame/packet scanning, no fixed file header: ADTS syncwords, MPEG start codes, 188/192-byte TS packets, MPEG-PS packs, MPA syncword scan, pickle opcode stream.
- no-spec (9) — the reference block is a placeholder or states the format is proprietary/undecodable, and no credible public spec was found (BR7, RAD, RAL, UPD, VI, VPM, NWD, FTH, …).
- chunk-scanning (8) — containers whose first object is at a variable offset or whose records are length-prefixed chains (binary CGM element stream, ICL EBCDIC records, LevelDB SSTable, PHZ/UOS/V3 ZIP saves whose samples are junk JS files, WK3 opcode records).
- no-header (7) — the format has no header by definition: raw code (.COM), raw disk/screen dumps (.SCR, .V64, .VB), raw MySQL row data (.MYD — the layout lives in the .frm), a raw zlib stream (.ADZ).
- EBML (3) — MKV/MKA/WEBM: variable-length EBML integers/elements, no fixed offsets.
Note: the autonomous driver's rounds 13–14 reported the round-12 numbers
(537/109/31/172) because the harness crashed on the 1–215 collector's
list-shaped manifest shard (load_manifests expected dicts); the driver
then stopped on the apparent plateau. The crash is fixed (list shards are
now normalized). The follow-up round then fixed 34 of the 38 FAILs with
per-format magics (ZIP/PK, RIFF, XML, ELF, OLE, Ogg, MZ, bzip2, xz, TAR,
J2C, MDMP, FCS, ftyp, EMF; CDR 81/82 swap; DNG to big-endian TIFF), added
24 genuine new samples (21 from re-trying the page links, 3 from web
search), dropped 14 bogus/mislabeled/truncated samples, and settled the
6 doubtful samples (550/554 kept; 005/024/373 dropped; 166 magic fixed).
Counts above are from a clean full re-run with all samples on disk
(752 files).
Fixes from the test loop live in tools/apply_testloop_overrides*.py
(ten batches so far, 351 overrides total): bogus magics removed
(##, ##TITLE= for the wrong format, xmlns:, 504b0506 as a file
magic, fishead, ENDFREQUENCIES, …), wrong extensions fixed (.JVX→.JXL,
.files→.MKA/.ICE, .LGA→.LHA, .SC7→.SD7, .OTS→.OTT, .OSB→.OSC), container
layouts added (ar, MZ/DOS, PDF, TIFF LE/BE, OLE/CFB), hand layouts for
~20 prominent formats (DEB, DICOM, EPS, EXR, HDF5, ELF64, TGA, S3M, IT,
3DS, FBX, MOBI, NetCDF, AU, DPX, CHM, RealMedia, DWF), and ~130 formats
verified as text from their samples and pages. Wrong samples
(404 pages, HTML error pages, S3 AccessDenied pages, distribution
archives, PDFs mislabeled as other formats, JS libraries saved as
samples, gzip files saved as .bson) are deleted, not tested.
Design
Table-driven, generic engine. All per-format knowledge lives in the
generated table src/formats.h (one entry per format: extension, name,
magic bytes + offset, field list of name/offset/size/kind, endianness).
The engine (src/sfile_lib.c, shipped as libsfile — see below)
contains no per-format decode logic — it walks the table, matches
magic, and formats the fields. The sfile CLI (src/sfile.c) is a
thin wrapper over the library: it parses arguments and prints the
library's sfile_result, as the human table or as JSON. A format is
never "guessed": the decode is derived from the collected reference
code, a published format spec (the hand overrides), or a verified
sample file, and the derivation is recorded per format in
src/formats.json.
Identification order. Longest magic match wins. Several formats share
a magic (all ZIP-based formats share PK\x03\x04; all RIFF formats share
RIFF); when that happens the filename extension disambiguates and the
other candidates are listed. If no magic matches, the extension is used.
If neither matches, sfile reports "unknown" with a hex dump.
Endianness. Per-format, detected from the reference code (use of
ntohl/ntohs/big-endian readers) or from the spec (PNG, TIFF, Java
class files are big-endian). Default is little-endian.
Text formats. XML files decode to document type + root element + version attribute; JSON to document type + first key; plain text to the first line.
Building
make # builds ./sfile and ./scar (gcc, -O2 -Wall -Wextra, no exotic deps)
make lib # builds libsfile.a + libsfile.so.1.1.0 (see below)
make stag sgeo # builds the geotag tools (see below)
make table # regenerate src/formats.h from tools/all_formats.cpp
make test # run the per-format test loop over samples/
make test-json # JSON output tests (parses + matches the text table)
make test-lib # library link test, static and shared
make test-geotag # geotag decoder tests (26 fixtures)
make install # install to /usr/local/bin (PREFIX=... to change)
Usage
sfile <file>... identify + decode the header (several files OK)
sfile --json <file>... same decode as JSON, one object per file (one per line)
sfile --list list all known formats (task, extension, name)
sfile --help
sfile --version
Exit codes: 0 identified, 1 usage error, 2 file unreadable, 3 unknown format. With several files the worst code wins (unreadable beats unknown).
JSON output
sfile --json prints the same decode as JSON (one compact object per
file, one per line): format, offsets, decoded fields, and geotags
when the file carries a location (from geotag_scan() — EXIF GPS,
XMP, QuickTime, GeoTIFF, EXR, PSD, CR3). See docs/json.md for the
schema and real examples.
$ sfile --json photo.png
{"file":"photo.png","size":29,"identified":true,"format":{"task":564,"ext":".PNG","name":"PNG image","kind":"binary","endian":"big"},"identified_by":"magic","magic":{"bytes":"89 50 4e 47 0d 0a 1a 0a","offset":0},"header":{"endian":"big","fields":[{"offset":0,"size":8,"name":"signature","type":"bytes","value":"89 50 4e 47 0d 0a 1a 0a"},{"offset":8,"size":4,"name":"ihdr_length","type":"u32","value":13},{"offset":12,"size":4,"name":"ihdr_type","type":"ascii","value":"IHDR"},{"offset":16,"size":4,"name":"width","type":"u32","value":800},{"offset":20,"size":4,"name":"height","type":"u32","value":600},{"offset":24,"size":1,"name":"bit_depth","type":"u8","value":8},{"offset":25,"size":1,"name":"color_type","type":"u8","value":2},{"offset":26,"size":1,"name":"compression","type":"u8","value":0},{"offset":27,"size":1,"name":"filter","type":"u8","value":0},{"offset":28,"size":1,"name":"interlace","type":"u8","value":0}]},"geotags":[]}
Library mode: libsfile
The decode engine is also a linkable C library — make lib builds
libsfile.a and libsfile.so.1.1.0, make install puts them in
$(PREFIX)/lib with sfile.h + geotag.h in $(PREFIX)/include.
Link it instead of shelling out to the sfile binary:
#include "sfile.h"
sfile_result r;
sfile_decode_file("photo.png", &r); /* 0 identified, 2 unreadable, 3 unknown */
printf("%s, task %d, %d fields\n", r.name, r.task, r.nfields);
sfile_free_result(&r);
gcc prog.c -lsfile # shared (after make install)
gcc prog.c libsfile.a # static
See docs/library.md for the full API, a worked example with real
output, and the tests (make test-lib).
Testing
tests/run_tests.py runs sfile over every sample in samples/ and
records, per format, whether it was identified correctly and whether a
header decode was produced:
- PASS — identified correctly AND a decode was produced.
- PARTIAL — identified, but no header layout exists yet (needs a hand override or a sample-derived layout).
- FAIL — misidentified or unknown.
- NO SAMPLE — no sample file could be found for that format.
Sample files come from the task pages' "Direct Download Links" first
(tools/sample_urls.json, 1,726 URLs across 849 tasks); where those links
are dead or missing, samples were found by searching the web. Each sample
is recorded in samples/manifest-*.json with its source URL and SHA-256.
The test loop is the ground truth for the table: a field layout that
decodes a real sample wrongly (wrong magic, fields past EOF, implausible
values) is fixed in tools/overrides.json and the table regenerated.
tests/results.json holds the latest per-format results.
Layout
sfile/
src/sfile.c the CLI (thin wrapper over libsfile)
src/sfile.h libsfile public API
src/sfile_lib.c the decode engine (generic; no per-format code)
src/geotag.c geotag decoders (EXIF/XMP/QuickTime/GeoTIFF/EXR/PSD/CR3)
src/geotag.h geotag_scan() / GeoResult API
src/scar.c file carver built on the format table
src/stag.c geotag CSV tabulator (see below)
src/sgeo.c geotag map plotter (see below)
src/geotag_client.c the stag/sgeo <-> sfile seam (runs sfile, parses "Geotagging:")
src/footers.h footer/trailer signatures used by scar
src/formats.h generated format table (do not edit by hand)
src/formats.json the table as JSON (source of truth for tests)
tools/gen_formats.py generator: reference code -> formats.json/.h
tools/all_formats.cpp the collected C/C++ reference code (833 blocks)
tools/overrides.json hand overrides (spec-derived layouts, magic fixes)
tools/sample_urls.json download links per task (from the task pages)
tools/get_sample_urls.py extracts sample_urls.json from the raw pages
tools/extract_cpp.py extracts all_formats.cpp from the raw pages
tests/run_tests.py the per-format test loop
tests/run_tests.sh the stag/sgeo test suite (11 checks, fake sfile + local tile server)
tests/test_json.py --json tests: parses + matches the text table (make test-json)
tests/test_lib.sh library link test, static + shared (make test-lib)
tests/test_library.c link-test program (decodes via the public API only)
tests/make_fixtures.py synthetic fixtures shared by the JSON/library tests
tests/test_scar.py synthetic-image test for scar (make test-scar)
tests/results.json latest test results
docs/scar.md scar usage, carving decisions, limits
docs/json.md --json output: schema, geotags, examples
docs/library.md libsfile: API, building, example, tests
docs/stag-sgeo.md stag/sgeo usage, CSV format, map + attribution, network dependency
docs/trip-path.md sgeo --trip: the journey as a polyline with time labels
docs/geotag-contract.md the sfile <-> stag/sgeo geotag seam (what sfile prints, what the client accepts)
samples/ one real sample file per format + manifests
Carving: scar
scar recovers deleted files from a raw disk image using the same
format table: it scans for known magics and carves out each file it
finds, with a report (offset, format, size, confidence) — see
docs/scar.md.
$ make scar
$ scar image.dd # carves into ./carved/, prints a report table
See docs/scar.md for a full example run (real output), how carving
decisions are made, and the limits.
Geotags: stag and sgeo
stag scans a directory of photos/videos and writes one CSV row per
file (file,format,latitude,longitude,altitude,datum,timestamp,source);
every scanned file gets a row, with empty geo fields when no location
was found. sgeo plots the geotagged files on an OpenStreetMap image
(one red marker each, attribution baked onto the PNG). sgeo --trip geotags.csv draws the same points as a journey instead: the rows in
timestamp order, connected as a polyline with time labels (see
docs/trip-path.md). Both run the
sfile binary and parse its Geotagging: section — they never parse
containers themselves; the seam is docs/geotag-contract.md.
$ make stag sgeo # build the geotag tools
$ stag photos/ # -> geotags.csv in the cwd
$ sgeo photos/ # -> map.png in the cwd (fetches OSM tiles at runtime)
Real output (San Francisco + Tokyo EXIF GPS, via the decoder build of sfile):
file,format,latitude,longitude,altitude,datum,timestamp,source
plain.jpg,JPEG image,,,,,,
sf_real.jpg,JPEG image,37.774929,-122.419418,12.000,WGS-84,2024-05-01 12:34:56,EXIF GPS IFD (JPEG APP1 segment)
tokyo_real.jpg,JPEG image,35.676200,139.650300,,WGS-84,,EXIF GPS IFD (JPEG APP1 segment)
sgeo needs network access to tile.openstreetmap.org when it runs,
and the © OpenStreetMap contributors attribution drawn on the image
must stay there. See docs/stag-sgeo.md for the full usage, the CSV
format and the empty-coords rule, the test suite
(tests/run_tests.sh, 11/11 pass), and the build caveat.
Sources
Format reference code: https://fileformat.vpscoder.com (849 task pages).
The C/C++ code there is the reference for each format's header structure;
sfile's table is derived from it, verified against real sample files,
and corrected where the reference code is wrong (the reference code is
AI-generated and is not always a correct spec — the test loop is what
catches that).
License
MIT, copyright 2026 cnmcdee.