commit 6990c64cf757d230800bacb489eb1db3fc790e3a
parent eabf429b8405a3c120b2409d20f6ec6329ef0589
Author: Mattias Andrée <maandree@kth.se>
Date: Fri, 20 Jan 2017 11:16:36 +0100
Fix blind-crop
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat:
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/TODO b/TODO
@@ -13,7 +13,6 @@ blind-find-frame a graphical tool for locating frames, should highlight key fram
Add [-j jobs] to blind-from-video and blind-to-video.
UNTESTED:
- blind-crop
blind-cut
blind-extend
blind-rewrite-head
diff --git a/src/blind-crop.c b/src/blind-crop.c
@@ -37,7 +37,8 @@ main(int argc, char *argv[])
stream.file = "<stdin>";
stream.fd = STDIN_FILENO;
einit_stream(&stream);
- if (left + width > stream.width || top + height > stream.height)
+ if (left > SIZE_MAX - width || left + width > stream.width ||
+ top > SIZE_MAX - height || top + height > stream.height)
eprintf("crop area extends beyond original image\n");
if (tile) {
fprint_stream_head(stdout, &stream);
@@ -59,10 +60,10 @@ main(int argc, char *argv[])
left *= stream.pixel_size;
if (!tile) {
- off = top * irown;
+ off = top * irown + left;
} else {
- off = (orown - (left % orown)) % orown;
- yoff = (height - (top % height)) % height;
+ off = (orown - left % orown) % orown;
+ yoff = (height - top % height) % height;
}
memcpy(buf, stream.buf, ptr = stream.ptr);
@@ -72,9 +73,9 @@ main(int argc, char *argv[])
memcpy(image + y * orown, buf + y * irown + off, orown);
} else {
for (ptr = y = 0; y < stream.height; y++) {
- p = buf + ((y + yoff) % height) * irown + left;
+ p = buf + ((y + yoff) % height + top) * irown;
for (x = 0; x < irown; x++, ptr++)
- image[ptr++] = p[(x + off) % orown];
+ image[ptr] = p[(x + off) % orown + left];
}
}
ewriteall(STDOUT_FILENO, image, m, "<stdout>");