Building TIFF Inspector: Exploring OCaml, TIFF Internals, and an In-Browser Playground

Hi everyone!

I’ve been building TIFF Inspector, a tool for looking inside TIFF files (directories, tags, storage layout, samples and planes), built on geocaml/ocaml-tiff.

It comes as a CLI, an HTTP API and a web UI. Every reported value says where it came from: read from the file, a spec default, or absent. Nothing is guessed.

What might interest OCaml folks

ocaml-tiff fixes. Testing on unusual files turned up a few issues, which I fixed in a vendored copy:

  • BigTIFF entries with several small values stored inline (for example, BitsPerSample=[8,8,8], as GDAL writes them) were unreadable.
  • Classic TIFF offsets of 2 GiB and above were sign-extended.
  • SampleFormat stored at an offset rather than inline was not read.
  • Entry introspection, so tools can see field types and counts.

Independent test fixtures. There are 21 small TIFFs generated by a separate Python writer that shares no code with the parser, plus golden outputs. They might be useful to ocaml-tiff as a conformance set, if the maintainers want them.

An in-browser playground. At /playground, you can write OCaml and run it against ocaml-tiff and the inspector core on sample files, with no install. It’s the toplevel compiled with js_of_ocaml (about 1.3 MB gzipped), running in a web worker. ;; is optional, and compile errors are underlined in the editor.

To get there, I wrote JavaScript implementations of the C primitives used by bstr and checkseum. I’d be glad to offer them upstream if that’s useful.

The server. It uses OCaml 5 with Eio and cohttp-eio. Each upload is inspected in a separate process with time and memory limits, with rate limiting and graceful shutdown. It runs in Docker on a free Render instance.

Feedback welcome

  • Does the JSON report shape work for other geospatial tooling?
  • geocaml maintainers: would you prefer the fixes as one PR or several small ones?
  • Any TIFFs that inspect incorrectly? Issues with a sample file are gold.

Thanks for reading!

1 Like

Hi Ridwan! Thanks for sharing!

I think the link to your github repository has a typo

Hi @RidwanAdebsoin,

Geocaml maintainer here. I have sent you some feedback about this project as a direct message on the OCaml Zulip.

So others know, as an OCaml Outreachy coordinator and mentor, I am working on a topic related to this over the coming months. You can find us on the OCaml Zulip, under the Outreachy channel. As I have mentioned on Zulip, we are tracking issues here and I welcome new issues being opened where users understand the problem and can easily reproduce it. Please bear in mind ocaml-tiff’s AI policy when opening issues and PRs (as well as Outreachy’s) – thanks.