Skip to content

Commit

Permalink
Merge pull request #813 from mapbox/decode-crash
Browse files Browse the repository at this point in the history
Guard against null data in the mbtiles file when decoding
  • Loading branch information
e-n-f authored Oct 31, 2019
2 parents ec00ac2 + 25bf395 commit 065cc1d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.34.6

* Fix crash when there are null entries in the metadata table

## 1.34.5

* Fix line numbers in GeoJSON feature parsing error messages
Expand Down
20 changes: 15 additions & 5 deletions decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,17 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
const unsigned char *name = sqlite3_column_text(stmt2, 0);
const unsigned char *value = sqlite3_column_text(stmt2, 1);

if (name == NULL || value == NULL) {
fprintf(stderr, "Corrupt mbtiles file: null metadata\n");
exit(EXIT_FAILURE);
}

if (exclude_meta.count((char *) name) == 0) {
if (within) {
state.json_comma_newline();
}
within = 1;

if (name == NULL || value == NULL) {
fprintf(stderr, "Corrupt mbtiles file: null metadata\n");
exit(EXIT_FAILURE);
}

state.json_write_string((char *) name);
state.json_write_string((char *) value);
}
Expand Down Expand Up @@ -413,6 +413,11 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
ty = (1LL << tz) - 1 - ty;
const char *s = (const char *) sqlite3_column_blob(stmt, 0);

if (s == NULL) {
fprintf(stderr, "Corrupt mbtiles file: null entry in tiles table\n");
exit(EXIT_FAILURE);
}

handle(std::string(s, len), tz, tx, ty, to_decode, pipeline, stats, state);
}

Expand Down Expand Up @@ -449,6 +454,11 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
int len = sqlite3_column_bytes(stmt, 0);
const char *s = (const char *) sqlite3_column_blob(stmt, 0);

if (s == NULL) {
fprintf(stderr, "Corrupt mbtiles file: null entry in tiles table\n");
exit(EXIT_FAILURE);
}

if (z != oz) {
fprintf(stderr, "%s: Warning: using tile %d/%u/%u instead of %d/%u/%u\n", fname, z, x, y, oz, ox, oy);
}
Expand Down
2 changes: 1 addition & 1 deletion version.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef VERSION_HPP
#define VERSION_HPP

#define VERSION "v1.34.5"
#define VERSION "v1.34.6"

#endif

0 comments on commit 065cc1d

Please sign in to comment.