diff mbox series

[FFmpeg-devel,5/5] avcodec/sga: Don't use GetBit-API for byte-aligned reads

Message ID GV1P250MB07372396742C9AB26314BD7A8F05A@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit c7ff0c3e4b990ad1484a023a073394aaf5d8a261
Headers show
Series [FFmpeg-devel,1/5] fftools/ffprobe: Fix memleak | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt July 31, 2023, 11:13 a.m. UTC
Use the bytestream2-API instead.
Should also fix Coverity issue #1473536 (which is about an unchecked
init_get_bits8()).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/sga.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Paul B Mahol July 31, 2023, 11:43 a.m. UTC | #1
Have you actually tested this?
Andreas Rheinhardt July 31, 2023, 11:44 a.m. UTC | #2
Paul B Mahol:
> Have you actually tested this?
> 

Yes.
https://samples.ffmpeg.org/game-formats/segacd/sga/doubleswitch/gameover.sga
executes this codepath.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/sga.c b/libavcodec/sga.c
index eae691adad..4ced6e9890 100644
--- a/libavcodec/sga.c
+++ b/libavcodec/sga.c
@@ -127,19 +127,18 @@  static int decode_index_palmap(SGAVideoContext *s, AVFrame *frame)
 
 static int decode_index_tilemap(SGAVideoContext *s, AVFrame *frame)
 {
-    GetByteContext *gb = &s->gb;
-    GetBitContext pm;
+    GetByteContext *gb = &s->gb, gb2;
 
     bytestream2_seek(gb, s->tilemapdata_offset, SEEK_SET);
     if (bytestream2_get_bytes_left(gb) < s->tilemapdata_size)
         return AVERROR_INVALIDDATA;
 
-    init_get_bits8(&pm, gb->buffer, s->tilemapdata_size);
+    gb2 = *gb;
 
     for (int y = 0; y < s->tiles_h; y++) {
         for (int x = 0; x < s->tiles_w; x++) {
             uint8_t tile[64];
-            int tilemap = get_bits(&pm, 16);
+            int tilemap = bytestream2_get_be16u(&gb2);
             int flip_x = (tilemap >> 11) & 1;
             int flip_y = (tilemap >> 12) & 1;
             int tindex = av_clip((tilemap & 511) - 1, 0, s->nb_tiles - 1);