Skip to content

Commit

Permalink
Verify w and h input multiplication overflow to rleEncode() (#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunchu authored Jun 27, 2024
1 parent c296000 commit d00d0cf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/datumaro/capi/pybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ struct RLE

RLE rleEncode(const byte *M, siz h, siz w)
{

siz j, k, a = w * h;

if (a / w != h)
throw std::runtime_error("result overflow. input size is too big.");

uint c;
byte p;
auto cnts = std::make_unique<std::vector<uint>>(a + 1);
Expand Down Expand Up @@ -82,6 +87,7 @@ py::dict pyRleEncode(py::array_t<std::uint8_t, py::array::f_style | py::array::f

const siz h = buf.shape[0];
const siz w = buf.shape[1];

const auto rle = rleEncode(static_cast<const byte *>(buf.ptr), h, w);

py::array_t<uint> cnts(rle.m);
Expand Down

0 comments on commit d00d0cf

Please sign in to comment.