Bug 342397 - There's signed interger overflow in Download Region window in "Number of tiles to download" and "Estimated Download size" fields
Summary: There's signed interger overflow in Download Region window in "Number of tile...
Status: RESOLVED FIXED
Alias: None
Product: marble
Classification: Applications
Component: general (show other bugs)
Version: 1.8 (KDE 4.13)
Platform: Ubuntu Linux
: NOR minor
Target Milestone: ---
Assignee: marble-bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-01 19:38 UTC by noktastrigo
Modified: 2015-02-08 10:56 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Downloading region dialog (260.67 KB, image/png)
2015-01-02 01:37 UTC, James W
Details
Downloading region dialog (buggy) (262.38 KB, image/png)
2015-01-02 23:20 UTC, James W
Details

Note You need to log in before you can comment on or make changes to this bug.
Description noktastrigo 2015-01-01 19:38:21 UTC
When choosing to download too many tiles it shows negative numbers in "Number of tiles to download" and "Estimated Download size" fields.

Reproducible: Always

Steps to Reproduce:
1. Choose OSM maps (hasn't tried on other maps) and show the whole globe
2. Click File -> Download Region
3. Choose "Visible region" and Zoom -> "Tile level range" from 2 to 16 (actually, from any to 16 will do)

Actual Results:  
Number of tiles to download: -1386718928
Estimated Download size: -1.80273e+10 kB

Expected Results:  
There must be real number of according tiles, obviosly positive.

Looks like a 32-bit signed integer overflow.
Comment 1 James W 2015-01-02 01:36:14 UTC
Hi there,
Are you running a 32 bit build of Marble? I cannot reproduce this with Marble 1.9.2 (64 bit).

(note: I'm a Google Code-in student)
Comment 2 James W 2015-01-02 01:37:24 UTC
Created attachment 90192 [details]
Downloading region dialog
Comment 3 noktastrigo 2015-01-02 13:06:21 UTC
Hi James!
I've installed Marble from Ubuntu Software Center on x64 Ubuntu, so i suppose it should be 64 bit version.

$marble -v
Qt: 4.8.6
KDE Development Platform: 4.13.3
Marble Virtual Globe: 1.8.3 (stable relase)
(I think I should post it earlier)

I've just found out that it really depends on the globe position. If instead of "Visible region" I choose "Specify region" N 90, W -180, E 180, S -55,8, then I get Number of tiles -363284952.
I think in your case you just got the same integer overflow, but the number just got positive again (the most significant bit became 0 again).
Comment 4 noktastrigo 2015-01-02 14:21:31 UTC
There are 2^(2*n) tiles on zoom level n. So there must be 4294967296 tiles for zoom level 16 to 16, 5368709120 tiles for zoom level 15 to 16, ..., 5726623056 tiles for zoom level 2 to 16 for the whole globe (from 85.0511 N to -85.0511 S). And on your screenshot there are much less tiles. Actually, 5726623056 mod 2^32 = 1431655760 - something around you've got.
(info about tiles here https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames)
Comment 5 James W 2015-01-02 23:19:30 UTC
Ah hah, the specify region option did it. Can confirm this on Marble 1.9.2 (64 bit).
Comment 6 James W 2015-01-02 23:20:04 UTC
Created attachment 90199 [details]
Downloading region dialog (buggy)
Comment 7 Dennis Nienhüser 2015-02-08 10:53:12 UTC
The tile count is passed as 64 bit integers, but in one calculation it uses 32 bit integers, leading to this issue. I'll push a fix shortly.
Comment 8 Dennis Nienhüser 2015-02-08 10:56:26 UTC
Git commit 36373c0e20403d5e1a1f0edf418eae593e701ee2 by Dennis Nienhüser.
Committed on 08/02/2015 at 10:50.
Pushed by nienhueser into branch 'master'.

Fix tile count calculation when tile number exceeds 32 bit range

M  +2    -1    src/lib/marble/TileCoordsPyramid.cpp

http://commits.kde.org/marble/36373c0e20403d5e1a1f0edf418eae593e701ee2