@@ -1155,7 +1155,8 @@ fn build_histogram(
11551155 let mut index: u64 = 0 ;
11561156 while let Some ( row) = rows. next ( ) . context ( "read histogram row" ) ? {
11571157 let row_zoom: u8 = row. get ( 0 ) ?;
1158- let length: u64 = row. get ( 1 ) ?;
1158+ let length: i64 = row. get ( 1 ) ?;
1159+ let length = u64:: try_from ( length) . context ( "tile length must be non-negative" ) ?;
11591160 if let Some ( target) = zoom
11601161 && row_zoom != target
11611162 {
@@ -1306,7 +1307,8 @@ fn build_zoom_histograms(
13061307 let mut total_index: u64 = 0 ;
13071308 while let Some ( row) = rows. next ( ) . context ( "read zoom histogram row" ) ? {
13081309 let zoom: u8 = row. get ( 0 ) ?;
1309- let length: u64 = row. get ( 1 ) ?;
1310+ let length: i64 = row. get ( 1 ) ?;
1311+ let length = u64:: try_from ( length) . context ( "tile length must be non-negative" ) ?;
13101312 total_index += 1 ;
13111313 let Some ( accum) = accums. get_mut ( & zoom) else {
13121314 continue ;
@@ -1471,7 +1473,8 @@ fn fetch_zoom_counts(conn: &Connection) -> Result<BTreeMap<u8, u64>> {
14711473 let mut counts = BTreeMap :: new ( ) ;
14721474 while let Some ( row) = rows. next ( ) . context ( "read zoom count row" ) ? {
14731475 let zoom: u8 = row. get ( 0 ) ?;
1474- let count: u64 = row. get ( 1 ) ?;
1476+ let count: i64 = row. get ( 1 ) ?;
1477+ let count = u64:: try_from ( count) . context ( "tile count must be non-negative" ) ?;
14751478 counts. insert ( zoom, count) ;
14761479 }
14771480 Ok ( counts)
@@ -1526,12 +1529,13 @@ pub fn inspect_mbtiles_with_options(path: &Path, options: InspectOptions) -> Res
15261529 let query = select_tile_count_query ( & conn, options. zoom . is_some ( ) ) ?;
15271530 let count = match options. zoom {
15281531 Some ( z) => conn
1529- . query_row ( & query, [ z] , |row| row. get ( 0 ) )
1532+ . query_row ( & query, [ z] , |row| row. get :: < _ , i64 > ( 0 ) )
15301533 . context ( "failed to read tile count (zoom)" ) ?,
15311534 None => conn
1532- . query_row ( & query, [ ] , |row| row. get ( 0 ) )
1535+ . query_row ( & query, [ ] , |row| row. get :: < _ , i64 > ( 0 ) )
15331536 . context ( "failed to read tile count" ) ?,
15341537 } ;
1538+ let count = u64:: try_from ( count) . context ( "tile count must be non-negative" ) ?;
15351539 if let Some ( spinner) = spinner {
15361540 spinner. finish_and_clear ( ) ;
15371541 }
@@ -1609,7 +1613,8 @@ pub fn inspect_mbtiles_with_options(path: &Path, options: InspectOptions) -> Res
16091613 let zoom: u8 = row. get ( 0 ) ?;
16101614 let x: u32 = row. get ( 1 ) ?;
16111615 let y: u32 = row. get ( 2 ) ?;
1612- let length: u64 = row. get ( 3 ) ?;
1616+ let length: i64 = row. get ( 3 ) ?;
1617+ let length = u64:: try_from ( length) . context ( "tile length must be non-negative" ) ?;
16131618 let tile_data: Option < Vec < u8 > > = if need_tile_data {
16141619 Some ( row. get ( 4 ) ?)
16151620 } else {
0 commit comments