fix read beyond buffer in topojson test

This commit is contained in:
Mickey Rose 2018-08-10 21:30:50 +02:00
parent ee28954786
commit 6a3452da96

View file

@ -65,7 +65,17 @@ bool parse_topology_string(std::string const& buffer, mapnik::topojson::topology
std::cerr << "failed to parse TopoJSON..." << std::endl;
std::cerr << ex.what() << std::endl;
std::cerr << "Expected: " << ex.which();
std::cerr << " Got: \"" << std::string(ex.where(), ex.where() + 200) << "...\"" << std::endl;
std::cerr << "\nGot: \"";
auto ctx = ex.where();
std::streamsize len = 0;
// stop before NUL terminator or after 200 bytes, whichever comes first
for (; ctx[len] && len < 200; ++len)
;
// extend to UTF-8 character boundary or 210 bytes, whichever comes first
for (; len < 210 && ((unsigned char)ctx[len] & 0xC0) == 0x80; ++len)
;
std::cerr.write(ctx, len);
std::cerr << (ctx[len] ? "..." : "") << '"' << std::endl;
return false;
}
return (itr == end);