diff options
author | Manuel Lauss <manuel.lauss@gmail.com> | 2025-03-11 13:20:05 +0100 |
---|---|---|
committer | Manuel Lauss <manuel.lauss@gmail.com> | 2025-03-19 20:58:46 +0100 |
commit | f6c6ba95fd69f51d7f30e8f201ff43050a53113f (patch) | |
tree | 640b6798697df9be838eb83791031d7a260d1f33 | |
parent | a48dd03fd9c7a114e183c621c5ec84eb2c8b440b (diff) | |
download | ffmpeg-f6c6ba95fd69f51d7f30e8f201ff43050a53113f.tar.gz |
avcodec/sanm: FOBJ left/top are signed values
The left/top parameters of a FOBJ are signed values. Adjust
codec1 code accordingly to not draw outside the buffer area.
Rebel Assault 1 makes heavy use of this.
Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
-rw-r--r-- | libavcodec/sanm.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index 49ac9bebfe..65ca525b9d 100644 --- a/libavcodec/sanm.c +++ b/libavcodec/sanm.c @@ -558,18 +558,18 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, const int out_size) static int old_codec1(SANMVideoContext *ctx, int top, int left, int width, int height) { - uint8_t *dst = ((uint8_t *)ctx->frm0) + left + top * ctx->pitch; - int i, j, len, flag, code, val, pos, end; + int i, j, len, flag, code, val, end, pxoff; + const int maxpxo = ctx->height * ctx->pitch; + uint8_t *dst = (uint8_t *)ctx->frm0; for (i = 0; i < height; i++) { - pos = 0; - if (bytestream2_get_bytes_left(&ctx->gb) < 2) return AVERROR_INVALIDDATA; len = bytestream2_get_le16u(&ctx->gb); end = bytestream2_tell(&ctx->gb) + len; + pxoff = left + ((top + i) * ctx->pitch); while (bytestream2_tell(&ctx->gb) < end) { if (bytestream2_get_bytes_left(&ctx->gb) < 2) return AVERROR_INVALIDDATA; @@ -577,25 +577,28 @@ static int old_codec1(SANMVideoContext *ctx, int top, code = bytestream2_get_byteu(&ctx->gb); flag = code & 1; code = (code >> 1) + 1; - if (pos + code > width) - return AVERROR_INVALIDDATA; if (flag) { val = bytestream2_get_byteu(&ctx->gb); - if (val) - memset(dst + pos, val, code); - pos += code; + if (val) { + for (j = 0; j < code; j++) { + if (pxoff >= 0 && pxoff < maxpxo) + *(dst + pxoff) = val; + pxoff++; + } + } else { + pxoff += code; + } } else { if (bytestream2_get_bytes_left(&ctx->gb) < code) return AVERROR_INVALIDDATA; for (j = 0; j < code; j++) { val = bytestream2_get_byteu(&ctx->gb); - if (val) - dst[pos] = val; - pos++; + if ((pxoff >= 0) && (pxoff < maxpxo) && val) + *(dst + pxoff) = val; + pxoff++; } } } - dst += ctx->pitch; } ctx->rotate_code = 0; @@ -1236,8 +1239,8 @@ static int old_codec48(SANMVideoContext *ctx, int width, int height) static int process_frame_obj(SANMVideoContext *ctx) { uint16_t codec = bytestream2_get_le16u(&ctx->gb); - uint16_t left = bytestream2_get_le16u(&ctx->gb); - uint16_t top = bytestream2_get_le16u(&ctx->gb); + int16_t left = bytestream2_get_le16u(&ctx->gb); + int16_t top = bytestream2_get_le16u(&ctx->gb); uint16_t w = bytestream2_get_le16u(&ctx->gb); uint16_t h = bytestream2_get_le16u(&ctx->gb); |