mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-03-25 05:15:16 +00:00
Report decompression errors in tippecanoe-decode
This commit is contained in:
parent
d1a0e495ce
commit
07ab900393
52
mvt.cpp
52
mvt.cpp
@ -34,25 +34,49 @@ int decompress(std::string const &input, std::string &output) {
|
||||
inflate_s.avail_in = 0;
|
||||
inflate_s.next_in = Z_NULL;
|
||||
if (inflateInit2(&inflate_s, 32 + 15) != Z_OK) {
|
||||
fprintf(stderr, "error: %s\n", inflate_s.msg);
|
||||
fprintf(stderr, "Decompression error: %s\n", inflate_s.msg);
|
||||
}
|
||||
inflate_s.next_in = (Bytef *) input.data();
|
||||
inflate_s.avail_in = input.size();
|
||||
size_t length = 0;
|
||||
do {
|
||||
output.resize(length + 2 * input.size());
|
||||
inflate_s.avail_out = 2 * input.size();
|
||||
inflate_s.next_out = (Bytef *) (output.data() + length);
|
||||
int ret = inflate(&inflate_s, Z_FINISH);
|
||||
if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) {
|
||||
fprintf(stderr, "error: %s\n", inflate_s.msg);
|
||||
inflate_s.next_out = (Bytef *) output.data();
|
||||
inflate_s.avail_out = output.size();
|
||||
|
||||
while (true) {
|
||||
size_t existing_output = inflate_s.next_out - (Bytef *) output.data();
|
||||
|
||||
output.resize(existing_output + 2 * inflate_s.avail_in + 100);
|
||||
inflate_s.next_out = (Bytef *) output.data() + existing_output;
|
||||
inflate_s.avail_out = output.size() - existing_output;
|
||||
|
||||
int ret = inflate(&inflate_s, 0);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Decompression error: ");
|
||||
if (ret == Z_DATA_ERROR) {
|
||||
fprintf(stderr, "data error");
|
||||
}
|
||||
if (ret == Z_STREAM_ERROR) {
|
||||
fprintf(stderr, "stream error");
|
||||
}
|
||||
if (ret == Z_MEM_ERROR) {
|
||||
fprintf(stderr, "out of memory");
|
||||
}
|
||||
if (ret == Z_BUF_ERROR) {
|
||||
fprintf(stderr, "no data in buffer");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
length += (2 * input.size() - inflate_s.avail_out);
|
||||
} while (inflate_s.avail_out == 0);
|
||||
if (ret == Z_STREAM_END) {
|
||||
break;
|
||||
}
|
||||
|
||||
// ret must be Z_OK or Z_NEED_DICT;
|
||||
// continue decompresing
|
||||
}
|
||||
|
||||
output.resize(inflate_s.next_out - (Bytef *) output.data());
|
||||
inflateEnd(&inflate_s);
|
||||
output.resize(length);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -90,7 +114,9 @@ bool mvt_tile::decode(std::string &message, bool &was_compressed) {
|
||||
|
||||
if (is_compressed(message)) {
|
||||
std::string uncompressed;
|
||||
decompress(message, uncompressed);
|
||||
if (decompress(message, uncompressed) == 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
src = uncompressed;
|
||||
was_compressed = true;
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user