Fix out-of-bounds image slices

This commit is contained in:
Rangi42
2025-07-01 18:06:03 -04:00
committed by Eldred Habert
parent 008920f533
commit 965288de38
12 changed files with 37 additions and 1 deletions

View File

@@ -863,7 +863,7 @@ int main(int argc, char *argv[]) {
}
fprintf(
stderr,
"\tInput image slice: %" PRIu32 "x%" PRIu32 " pixels starting at (%" PRId32 ", %" PRId32
"\tInput image slice: %" PRIu16 "x%" PRIu16 " pixels starting at (%" PRIu16 ", %" PRIu16
")\n",
options.inputSlice.width,
options.inputSlice.height,

View File

@@ -226,6 +226,30 @@ public:
if (options.inputSlice.height == 0 && height % 8 != 0) {
fatal("Image height (%" PRIu32 " pixels) is not a multiple of 8!", height);
}
if (options.inputSlice.right() > width || options.inputSlice.bottom() > height) {
error(
"Image slice ((%" PRIu16 ", %" PRIu16 ") to (%" PRIu32 ", %" PRIu32
")) is outside the image bounds (%" PRIu32 "x%" PRIu32 ")!",
options.inputSlice.left,
options.inputSlice.top,
options.inputSlice.right(),
options.inputSlice.bottom(),
width,
height
);
if (options.inputSlice.width % 8 == 0 && options.inputSlice.height % 8 == 0) {
fprintf(
stderr,
"note: Did you mean the slice \"%" PRIu32 ",%" PRIu32 ":%" PRId32 ",%" PRId32
"\"? (width and height are in tiles, not pixels!)\n",
options.inputSlice.left,
options.inputSlice.top,
options.inputSlice.width / 8,
options.inputSlice.height / 8
);
}
giveUp();
}
pixels.resize(static_cast<size_t>(width) * static_cast<size_t>(height));