mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 10:25:41 +02:00
Report decompression errors in tippecanoe-decode
This commit is contained in:
@@ -34,25 +34,49 @@ int decompress(std::string const &input, std::string &output) {
|
|||||||
inflate_s.avail_in = 0;
|
inflate_s.avail_in = 0;
|
||||||
inflate_s.next_in = Z_NULL;
|
inflate_s.next_in = Z_NULL;
|
||||||
if (inflateInit2(&inflate_s, 32 + 15) != Z_OK) {
|
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.next_in = (Bytef *) input.data();
|
||||||
inflate_s.avail_in = input.size();
|
inflate_s.avail_in = input.size();
|
||||||
size_t length = 0;
|
inflate_s.next_out = (Bytef *) output.data();
|
||||||
do {
|
inflate_s.avail_out = output.size();
|
||||||
output.resize(length + 2 * input.size());
|
|
||||||
inflate_s.avail_out = 2 * input.size();
|
while (true) {
|
||||||
inflate_s.next_out = (Bytef *) (output.data() + length);
|
size_t existing_output = inflate_s.next_out - (Bytef *) output.data();
|
||||||
int ret = inflate(&inflate_s, Z_FINISH);
|
|
||||||
if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) {
|
output.resize(existing_output + 2 * inflate_s.avail_in + 100);
|
||||||
fprintf(stderr, "error: %s\n", inflate_s.msg);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
length += (2 * input.size() - inflate_s.avail_out);
|
if (ret == Z_STREAM_END) {
|
||||||
} while (inflate_s.avail_out == 0);
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ret must be Z_OK or Z_NEED_DICT;
|
||||||
|
// continue decompresing
|
||||||
|
}
|
||||||
|
|
||||||
|
output.resize(inflate_s.next_out - (Bytef *) output.data());
|
||||||
inflateEnd(&inflate_s);
|
inflateEnd(&inflate_s);
|
||||||
output.resize(length);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +114,9 @@ bool mvt_tile::decode(std::string &message, bool &was_compressed) {
|
|||||||
|
|
||||||
if (is_compressed(message)) {
|
if (is_compressed(message)) {
|
||||||
std::string uncompressed;
|
std::string uncompressed;
|
||||||
decompress(message, uncompressed);
|
if (decompress(message, uncompressed) == 0) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
src = uncompressed;
|
src = uncompressed;
|
||||||
was_compressed = true;
|
was_compressed = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user