[binaryToString] Fixed overread when passing start > 0

binaryToString(DataBuf&) only calls the C-array version. Unfortunately, its
safety check is flawed, as it only works when start is 0 (probably due to its
conterintuitive interface).
binaryToString(byte*) formats the range (start,start+size) => we have to trimm
size if size + start is larger than the DataBuf's size_
v0.27.3
Dan Čermák 7 years ago
parent bfd84ddf5a
commit a48d0347b7

@ -80,8 +80,9 @@ namespace Exiv2
std::string binaryToString(const DataBuf& buf, size_t size, size_t start /*=0*/)
{
if (size > (size_t)buf.size_)
size = (size_t)buf.size_;
if (size + start > static_cast<size_t>(buf.size_)) {
size = static_cast<size_t>(buf.size_) - start;
}
return binaryToString(buf.pData_, size, start);
}

Loading…
Cancel
Save