Whole file
protomaps/pmtiles
The author described this change as “python: raise errors in overflow and invalid tile ID cases”. It counts as a record because the check below fails on the code as it stood at b23c98dd3 and passes on 78cde0d51, with nothing else changed between the two runs.
Projectprotomaps/pmtiles
Fix saved2022-12-22
Sharing licenceBSD-3-Clause · LICENSE
Change size+6 −3
What the code was meant to do, written into the code itself as a save note
python: raise errors in overflow and invalid tile ID cases
The change
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | 43 | def zxy_to_tileid(z, x, y): | |
| 44 | + | if z > 31: | |
| 45 | + | raise OverflowError("tile zoom exceeds 64-bit limit") | |
| 46 | + | if x > (1 << z) - 1 or y > (1 << z) - 1: | |
| 47 | + | raise ValueError("tile x/y outside zoom level bounds") | |
| 44 | 48 | acc = 0 | |
| 45 | 49 | tz = 0 | |
| 46 | 50 | while tz < z: | |
| ⋯ | |||
| 70 | 74 | def tileid_to_zxy(tile_id): | |
| 71 | 75 | num_tiles = 0 | |
| 72 | 76 | acc = 0 | |
| 73 | - | z = 0 | |
| 74 | - | while True: | |
| 77 | + | for z in range(0,32): | |
| 75 | 78 | num_tiles = (1 << z) * (1 << z) | |
| 76 | 79 | if acc + num_tiles > tile_id: | |
| 77 | 80 | return t_on_level(z, tile_id - acc) | |
| 78 | 81 | acc += num_tiles | |
| 79 | - | z += 1 | |
| 82 | + | raise OverflowError("tile zoom exceeds 64-bit limit") | |
| 80 | 83 | ||
| 81 | 84 | ||
| 82 | 85 | def find_tile(entries, tile_id): | |
The check that tells the two apart
fail→pass·python/test/test_tile.py::TestTileId::test_invalid_tiles
Check file python/test/test_tile.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itb23c98dd390db79e2243b0a7015d008b2f3f45f9
Broken version dated2022-12-22
Modulepython.pmtiles.tile
Units changedtileid_to_zxy, zxy_to_tileid
Fingerprint733971194e8dab8d
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.