Skip to content

Add additive 64-bit TIFF input API - #197

Merged
danoli3 merged 8 commits into
masterfrom
experiment/largefile-additive-io64
Oct 28, 2026
Merged

danoli3 merged 8 commits into
masterfrom
experiment/largefile-additive-io64

Conversation

@danoli3

@danoli3 danoli3 commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Add a 64-bit TIFF/BigTIFF input path so small images can be decoded when their directories, metadata, thumbnails or pixel strips lie beyond 2 GiB or 4 GiB, including on Windows where long remains 32-bit.

FreeImageIO64, FreeImage_Load64 and FreeImage_LoadFromHandle64 are additive APIs. Existing FreeImageIO, load signatures and the external Plugin descriptor retain their layouts and ABI. TIFF dispatch stays private. The new path supports read-only custom streams, checks callbacks and transfers, propagates I/O failures and respects disabled plugins. Default file callbacks use _fseeki64/_ftelli64 on Windows and wide POSIX file offsets.

Scope is single-image TIFF input. Other formats return NULL through the new APIs; saving, multipage, Unicode filename entry points and the DWORD-sized memory API are outside this change. PNG/BMP release fixtures exercise their existing loaders.

The Published large-file image tests workflow downloads the 91 individual payloads from test-fixtures-io64-v1, pins the manifest SHA-256, and verifies each payload before extraction. It tests and removes one image at a time, including after failure/timeout. Coverage includes filename/custom-stream loading, native pixels, high-offset Exif/thumbnails, header-only TIFF loading, malformed data, and nested multilingual paths. Windows opens UTF-16 paths through the custom-stream API. The matrix covers Linux ASan, macOS C++11, MSVC x64 DLL and MSVC Win32.

Four malformed strip/offset fixtures are known to return a bitmap instead of being rejected on the earlier #197 baseline. They are explicitly reported as XFAIL when the decoder returns the dedicated status and the pinned manifest declares the known behavior. Other failures block CI; successful rejection passes normally. These failures remain visible rather than being counted as passing rejection tests.

Validation on master 9a22df4 (fixture PR #233 merged):

  • The original four PR patches rebase unchanged (git range-diff).
  • macOS AppleClang C++17 static build with bundled codecs and ASan: all 14 CTest targets pass, including the large-offset callback regression. Optional HEIF/JXL codecs were disabled for this build.
  • The exact new CI decoder/runner command against the published release assets reports 87 passed, 4 known failures, 0 unexpected failures, with no ASan reports and all temporary payloads removed.
  • All 16 packaging/runner tests pass, including checksum pinning, sparse extraction, cleanup after failure/timeout and opt-in handling of declared known failures.
  • The new decoder passes 32-bit MinGW C++11 and 64-bit MinGW C++17 syntax checks. Workflow YAML and whitespace checks pass.

Published-fixture CI passes on all four platforms: Linux ASan, macOS C++11, MSVC x64 DLL and MSVC Win32. Both native Windows runs report 87 passed, 4 documented known failures and 0 unexpected failures. CMake supplies the decoder executable path so per-target Windows output directories are handled correctly.

@danoli3

danoli3 commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

Just testing approaches and ideas

@danoli3
danoli3 force-pushed the experiment/largefile-additive-io64 branch from 5e8c22e to 0d5f5e8 Compare October 25, 2026 13:27
@danoli3
danoli3 marked this pull request as ready for review October 26, 2026 07:45
@danoli3

danoli3 commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

The new public entry points in this PR are:

  • FreeImage_Load64(FIF_TIFF, filename, flags) — load from a filename using the library's default 64-bit file I/O.
  • FreeImage_LoadFromHandle64(FIF_TIFF, &io64, handle, flags) — load from a custom seekable stream using FreeImageIO64.
  • FreeImageIO64 uses FI_ReadProc64, FI_WriteProc64, FI_SeekProc64 and FI_TellProc64. For loading, read/seek/tell are required; write may be NULL. The caller retains ownership of a custom handle.

These APIs are available on Windows, Linux and macOS, and are not restricted to 64-bit processes. The final CI passes Linux x86 and Windows MinGW32 static/DLL tests, as well as the native 64-bit builds. The tests exercise TIFF positions beyond both 2 GiB and 4 GiB.

No additional user-facing “64-bit” define or CMake option is required to enable these APIs. Their offset types are explicitly int64_t/uint64_t. CMake supplies _FILE_OFFSET_BITS=64 for the library on non-Apple Unix targets, and the default I/O implementation selects wide POSIX offsets before system headers. Windows uses _fseeki64/_ftelli64; POSIX uses fseeko/ftello.

For custom callbacks, the application's implementation must also support wide file positions. On 32-bit POSIX, that normally means compiling that callback code with _FILE_OFFSET_BITS=64 before including system headers and using fseeko/ftello. The library's private compile definition does not configure application source files. A wrapper around 32-bit fseek/ftell would retain their limits.

Current scope is single-image TIFF/BigTIFF input only. Other formats return NULL through these entry points. Existing load APIs, FreeImageIO, and the external Plugin descriptor retain their original ABI. Saving, multipage operations, the DWORD-sized memory-stream API and the process's available pixel-buffer address space are not widened by this change.

@danoli3

danoli3 commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Okay looking to merge this any comments @thbeu @haobinnan

@danoli3
danoli3 force-pushed the experiment/largefile-additive-io64 branch from 10129ae to 6c964f3 Compare October 27, 2026 19:52
@thbeu

thbeu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Okay looking to merge this any comments @thbeu @haobinnan

I already replied here

@haobinnan

Copy link
Copy Markdown
Contributor

Okay looking to merge this any comments @thbeu @haobinnan

I think this can be merged.

@danoli3
danoli3 force-pushed the experiment/largefile-additive-io64 branch from 6c964f3 to 122dfd2 Compare October 28, 2026 12:26
@danoli3

danoli3 commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner Author

The one unexpected failure was a GitHub release-asset HTTP 500 during download, before the decoder ran. All valid large-file TIFF fixtures passed, including files with offsets above 4 GiB.

Updated results below are from the successful run 40698598326, commit 65feb7c76bae455c0cec14970aed2ee2621b7441. The previous run 40693081690 had 86 passes, four known failures and one HTTP 500 on macOS when fetching paths/日本語/broken image.tif; every other platform had 87 passes and four known failures.

Platform Passed Known malformed-input failures Unexpected failures
Linux ASan 87 4 0
macOS C++11 87 4 0
MSVC x64 DLL 87 4 0
MSVC Win32 87 4 0

What the 64-bit test actually checks: TIFF fixtures already use FreeImage_Load64 and FreeImage_LoadFromHandle64, plus header-only loading for valid TIFFs. Valid images must have the expected 1×1 dimensions and RGB (18, 52, 86); the high-offset Exif/thumbnail fixture also checks its metadata and thumbnail pixels. On Windows, multilingual paths are opened using UTF-16 and passed through the handle API. PNG/BMP exercise the existing loaders because the added API is TIFF-only.

Do we need a passing 64-bit test? Those positive tests are already present: classic TIFF strips above 2 GiB and just below 4 GiB; BigTIFF strips/IFDs above 4 GiB; both byte orders; and Exif/thumbnails above 4 GiB. They pass on all four platforms, even a 32-bit Windows process using 64-bit file offsets. LargeFileTIFFTest also covers wide callbacks, missing/invalid callbacks, failing seeks/reads, and out-of-range offsets. The image size is tiny; the sparse files exercise large offsets without allocating multi-gigabyte bitmaps.

Why the four XFAIL cases remain: their intended outcome is rejection. Three malformed TIFFs are already being tested through the 64-bit API; wider offsets do not repair absent/truncated pixel data. The BMP case uses the existing BMP API. These are recorded acceptance bugs, not valid large images that should start decoding after widening offsets. A future loader fix should make the original rejection assertions pass; changing the expectation to successful decoding would hide the bugs.

Fix pushed: 65feb7c retries transient HTTP/network errors up to four attempts (1, 2, 4 second delays). Persistent errors, hash mismatches, oversized responses and decoder failures still fail. All 23 packaging/runner tests pass locally, including a simulated HTTP 500 followed by a successful download; that recovery regression fails against the pre-fix runner. Cross-platform verification passed on all four platforms. The 23 runner tests and LargeFileTIFFTest also passed on all four platforms.

PASS means the expected outcome occurred: valid input decoded correctly, or malformed input was rejected. XFAIL means the malformed input incorrectly returned a bitmap and is explicitly recorded in the pinned manifest. HTTP 500 means the decoder was never reached.

All 91 images: expected result, per-platform result and explanation
Image Expected Linux ASan macOS C++11 MSVC x64 MSVC Win32 Explanation
broken/bigtiff-strip-past-eof.tif reject XFAIL XFAIL XFAIL XFAIL Strip offset points beyond EOF; loader returns a bitmap instead of rejecting it.
broken/bigtiff-truncated-ifd-above-4g.tif reject PASS PASS PASS PASS Correctly rejected malformed input: truncated ifd above 4g.
broken/bigtiff-truncated-strip-above-4g.tif reject XFAIL XFAIL XFAIL XFAIL Only 2 of the required 3 pixel bytes exist above 4 GiB; loader returns a bitmap.
broken/bmp-empty.bmp reject PASS PASS PASS PASS Correctly rejected malformed input: empty.
broken/bmp-offset-past-eof.bmp reject XFAIL XFAIL XFAIL XFAIL BMP pixel offset is above 2 GiB and beyond EOF; legacy BMP loader returns a bitmap.
broken/bmp-truncated-header.bmp reject PASS PASS PASS PASS Correctly rejected malformed input: truncated header.
broken/bmp-truncated-pixels.bmp reject PASS PASS PASS PASS Correctly rejected malformed input: truncated pixels.
broken/classic-truncated-strip-above-2g.tif reject XFAIL XFAIL XFAIL XFAIL Only 2 of the required 3 pixel bytes exist above 2 GiB; loader returns a bitmap.
broken/empty.tif reject PASS PASS PASS PASS Correctly rejected malformed input: empty.
broken/ifd-outside-int64.tif reject PASS PASS PASS PASS Correctly rejected malformed input: ifd outside int64.
broken/ifd-past-eof.tif reject PASS PASS PASS PASS Correctly rejected malformed input: ifd past eof.
broken/invalid-offset-width.tif reject PASS PASS PASS PASS Correctly rejected malformed input: invalid offset width.
broken/overflowing-ifd-count.tif reject PASS PASS PASS PASS Correctly rejected malformed input: overflowing ifd count.
broken/png-empty.png reject PASS PASS PASS PASS Correctly rejected malformed input: empty.
broken/png-truncated-header.png reject PASS PASS PASS PASS Correctly rejected malformed input: truncated header.
broken/png-truncated-pixels.png reject PASS PASS PASS PASS Correctly rejected malformed input: truncated pixels.
broken/truncated-header.tif reject PASS PASS PASS PASS Correctly rejected malformed input: truncated header.
broken/truncated-ifd.tif reject PASS PASS PASS PASS Correctly rejected malformed input: truncated ifd.
broken/wrong-magic.tif reject PASS PASS PASS PASS Correctly rejected malformed input: wrong magic.
broken/zero-height.tif reject PASS PASS PASS PASS Correctly rejected malformed input: zero height.
broken/zero-width.tif reject PASS PASS PASS PASS Correctly rejected malformed input: zero width.
paths/combining-é/broken image.bmp reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/combining-é/broken image.png reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/combining-é/broken image.tif reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/combining-é/valid image.bmp decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/combining-é/valid image.png decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/combining-é/valid image.tif decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/emoji-🧪/broken image.bmp reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/emoji-🧪/broken image.png reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/emoji-🧪/broken image.tif reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/emoji-🧪/valid image.bmp decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/emoji-🧪/valid image.png decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/emoji-🧪/valid image.tif decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/spaces in name/broken image.bmp reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/spaces in name/broken image.png reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/spaces in name/broken image.tif reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/spaces in name/valid image.bmp decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/spaces in name/valid image.png decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/spaces in name/valid image.tif decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/Ελληνικά/broken image.bmp reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/Ελληνικά/broken image.png reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/Ελληνικά/broken image.tif reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/Ελληνικά/valid image.bmp decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/Ελληνικά/valid image.png decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/Ελληνικά/valid image.tif decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/Кириллица/broken image.bmp reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/Кириллица/broken image.png reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/Кириллица/broken image.tif reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/Кириллица/valid image.bmp decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/Кириллица/valid image.png decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/Кириллица/valid image.tif decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/العربية/broken image.bmp reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/العربية/broken image.png reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/العربية/broken image.tif reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/العربية/valid image.bmp decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/العربية/valid image.png decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/العربية/valid image.tif decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/हिन्दी/broken image.bmp reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/हिन्दी/broken image.png reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/हिन्दी/broken image.tif reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/हिन्दी/valid image.bmp decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/हिन्दी/valid image.png decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/हिन्दी/valid image.tif decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/中文/broken image.bmp reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/中文/broken image.png reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/中文/broken image.tif reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/中文/valid image.bmp decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/中文/valid image.png decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/中文/valid image.tif decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/日本語/broken image.bmp reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/日本語/broken image.png reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/日本語/broken image.tif reject PASS PASS PASS PASS Correctly rejected on all platforms. Previous macOS run failed during download (HTTP 500), before decoding.
paths/日本語/valid image.bmp decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/日本語/valid image.png decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/日本語/valid image.tif decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/한국어/broken image.bmp reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/한국어/broken image.png reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/한국어/broken image.tif reject PASS PASS PASS PASS Correctly rejected the malformed six-byte payload at this path.
paths/한국어/valid image.bmp decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/한국어/valid image.png decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
paths/한국어/valid image.tif decode PASS PASS PASS PASS Decoded expected pixels at the multilingual/spaced path.
valid/bigtiff-big-endian-above-4g.tif decode PASS PASS PASS PASS Decoded expected pixels; bigtiff big endian above 4g.
valid/bigtiff-ifd-exif-thumbnail-above-4g.tif decode PASS PASS PASS PASS Decoded expected pixels; bigtiff ifd exif thumbnail above 4g. Exif and thumbnail verified.
valid/bigtiff-small.tif decode PASS PASS PASS PASS Decoded expected pixels; bigtiff small.
valid/bigtiff-strip-above-4g.tif decode PASS PASS PASS PASS Decoded expected pixels; bigtiff strip above 4g.
valid/classic-big-endian-above-2g.tif decode PASS PASS PASS PASS Decoded expected pixels; classic big endian above 2g.
valid/classic-small.tif decode PASS PASS PASS PASS Decoded expected pixels; classic small.
valid/classic-strip-above-2g.tif decode PASS PASS PASS PASS Decoded expected pixels; classic strip above 2g.
valid/classic-strip-below-4g.tif decode PASS PASS PASS PASS Decoded expected pixels; classic strip below 4g.
valid/small.bmp decode PASS PASS PASS PASS Decoded expected pixels; non TIFF fallback.
valid/small.png decode PASS PASS PASS PASS Decoded expected pixels; non TIFF fallback.

@danoli3
danoli3 merged commit 94d4a40 into master Oct 28, 2026
85 checks passed
@danoli3 danoli3 mentioned this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants