Skip to content

Fix microtar tar header size field on MinGW Windows#7467

Merged
DennisOSRM merged 1 commit intoProject-OSRM:masterfrom
jrklasen:fix/microtar-mingw-size-format
Apr 11, 2026
Merged

Fix microtar tar header size field on MinGW Windows#7467
DennisOSRM merged 1 commit intoProject-OSRM:masterfrom
jrklasen:fix/microtar-mingw-size-format

Conversation

@jrklasen
Copy link
Copy Markdown
Contributor

On Windows (LLP64), long is 32-bit even on x86_64. The _MSC_VER guard in microtar correctly used %llo for MSVC but fell through to %lo for MinGW, causing the bug in the Julia binary of OSRM.

Replace the platform-specific _MSC_VER ifdef with portable uint64_t and <inttypes.h> format macros (SCNo64/PRIo64), which are correct on all platforms and compilers.

With this fix, we get the tests in the Julia wrapper passing. See OpenSourceRoutingMachine.jl and the build recipe, which contains the patch currently.

PS: It would be great if we could get a new point release we could refer to downstream once this is merged.

On Windows (LLP64), `long` is 32-bit even on x86_64. The `_MSC_VER`
guard in microtar correctly used `%llo` for MSVC but fell through to
`%lo` for MinGW, causing:

- sscanf with `%lo`: writes only 4 bytes into the 8-byte `h->size`
  field, leaving upper bytes uninitialized. Any subsequent size
  comparison fails, producing "Datatype size does not match file size"
  errors on osrm_fingerprint.meta.

- sprintf with `%lo`: reads only the lower 32 bits, producing
  incorrect tar headers for files above 4 GB.

Replace the platform-specific `_MSC_VER` ifdef with portable
`uint64_t` and `<inttypes.h>` format macros (`SCNo64`/`PRIo64`),
which are correct on all platforms and compilers.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect TAR header size field formatting/parsing on MinGW Windows (LLP64) by avoiding long-based %lo formatting and switching to uint64_t + <inttypes.h> format macros, ensuring correct behavior across compilers/platforms (notably for downstream Julia builds).

Changes:

  • Add <inttypes.h> include for portable SCNo64 / PRIo64 usage.
  • Parse the TAR size field into a uint64_t via SCNo64, then cast to mtar_size_t.
  • Format the TAR size field using PRIo64 with an explicit uint64_t cast.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@DennisOSRM DennisOSRM enabled auto-merge (squash) April 11, 2026 13:33
@DennisOSRM DennisOSRM merged commit 7a6cc9e into Project-OSRM:master Apr 11, 2026
27 checks passed
@jrklasen jrklasen deleted the fix/microtar-mingw-size-format branch April 11, 2026 13:37
@jrklasen
Copy link
Copy Markdown
Contributor Author

Thanks @DennisOSRM for swiftly merging this. Would it be possible to get a point release?

@DennisOSRM
Copy link
Copy Markdown
Collaborator

Thanks @DennisOSRM for swiftly merging this. Would it be possible to get a point release?

new release coming soon

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