Skip to content

Write PMTiles archives in binary mode#888

Open
Symmetricity wants to merge 1 commit into
systemed:masterfrom
Symmetricity:fix/pmtiles-binary-mode
Open

Write PMTiles archives in binary mode#888
Symmetricity wants to merge 1 commit into
systemed:masterfrom
Symmetricity:fix/pmtiles-binary-mode

Conversation

@Symmetricity
Copy link
Copy Markdown

This PR is AI generated.

Write PMTiles archives in binary mode

PMTiles archives contain compressed binary tile, directory, and metadata
payloads. On Windows, an std::ofstream opened in text mode can translate
newline bytes while writing. When that happens, the bytes written to disk no
longer match the offsets and lengths tilemaker has already recorded in the
PMTiles header.

Open the PMTiles output stream with std::ios::binary and use explicit
write() calls for compressed string payloads. This keeps the on-disk byte
count aligned with the PMTiles header and matches how the existing code already
writes other binary data.

The change is intentionally small: it only touches PMTiles file writes in
src/pmtiles.cpp.

Reproduce

On Windows, build tilemaker from current master, then generate a PMTiles
archive:

tilemaker liechtenstein.osm.pbf --config=resources/config-openmaptiles.json --process=resources/process-openmaptiles.lua --output=liechtenstein.pmtiles --verbose

Verify the archive:

pmtiles verify liechtenstein.pmtiles

Before this change, Windows-generated PMTiles archives can fail verification
with a header length mismatch:

Failed to verify archive, total length of archive ... does not match header ...

After this change, the same Windows PMTiles outputs verify successfully.

Testing

  • git diff --check
  • cmake -S . -B build-pmtiles-binary-mode -DCMAKE_BUILD_TYPE=RelWithDebInfo
  • cmake --build build-pmtiles-binary-mode --target tilemaker -j2
  • ./build-pmtiles-binary-mode/tilemaker test/monaco.pbf --config=resources/config-openmaptiles.json --process=resources/process-openmaptiles.lua --output=/tmp/tilemaker-pmtiles-binary-mode.pmtiles --verbose
  • pmtiles verify /tmp/tilemaker-pmtiles-binary-mode.pmtiles

A stacked fork CI run also verified the Windows PMTiles outputs successfully
with pmtiles verify. The overall run still failed because the new generated
tile verifier detected existing semantic differences between repeated tile
generation runs; that is separate from this PMTiles archive-structure fix.

Related Issues And PRs

I did not find an open upstream issue, PR, or discussion that directly reports
this Windows text-mode PMTiles archive corruption.

Related PMTiles context:

PMTiles files contain compressed binary tile and directory payloads.
On Windows, opening the output stream in text mode can translate
newline bytes as they are written. That changes the number of bytes
written to disk without changing the offsets and lengths recorded in
the PMTiles header.

Open the PMTiles stream in binary mode and write compressed strings
with write(). This preserves the existing format on POSIX while keeping
Windows output byte counts aligned with the header.
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.

1 participant