Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 11/12] avcodec/vlc, bitstream: Fix multi VLC with uint8_t syms on BE
Date: Sat, 30 Mar 2024 04:15:11 +0100
Message-ID: <GV1P250MB0737F1256A349CF58A18D4F58F392@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <GV1P250MB07377A6CF76BB88E41854D698F3A2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>

VLC_MULTI_ELEM contains an uint8_t array that is supposed
to be treated as an array of uint16_t when the used symbols
have a size of two; otherwise it should be treated as just
an array of uint8_t, but it was not always treated that way:

vlc_multi_gen() initialized the first entry of the array
by writing the symbol via AV_WN16; on big endian systems,
the intended value was instead written into the second entry
of the array (where it would likely be overwritten lateron
during initialization).

read_vlc_multi() also treated this case incorrectly: In case
the code is so long that it needs a classical multi-stage lookup,
the symbol has been written to the destination as if via AV_WN16.
On little endian systems, this sets the correct first symbol and
clobbers (zeroes) the next one, but the next one will be overwritten
lateron anyway, so it won't be recognized. But on big-endian systems,
the first symbol will be set to zero and the actually read symbol
will be put into the slot for the next one (where it will be overwritten
lateron).

This commit fixes this; this fixes the magicyuv and utvideo FATE-tests
on big endian arches.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/bitstream_template.h | 8 ++++++--
 libavcodec/get_bits.h           | 3 ++-
 libavcodec/magicyuv.c           | 2 +-
 libavcodec/utvideodec.c         | 2 +-
 libavcodec/vlc.c                | 5 ++++-
 5 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/libavcodec/bitstream_template.h b/libavcodec/bitstream_template.h
index 4f3d07275f..c8e4a5131e 100644
--- a/libavcodec/bitstream_template.h
+++ b/libavcodec/bitstream_template.h
@@ -536,7 +536,8 @@ static inline int BS_FUNC(read_vlc)(BSCTX *bc, const VLCElem *table,
 static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t dst[8],
                                           const VLC_MULTI_ELEM *const Jtable,
                                           const VLCElem *const table,
-                                          const int bits, const int max_depth)
+                                          const int bits, const int max_depth,
+                                          const int symbols_size)
 {
     unsigned idx = BS_FUNC(peek)(bc, bits);
     int ret, nb_bits, code, n = Jtable[idx].len;
@@ -554,7 +555,10 @@ static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t dst[8],
                 code = BS_FUNC(priv_set_idx)(bc, code, &n, &nb_bits, table);
             }
         }
-        AV_WN16(dst, code);
+        if (symbols_size == 1)
+            *dst = code;
+        else
+            AV_WN16(dst, code);
         ret = n > 0;
     }
     BS_FUNC(priv_skip_remaining)(bc, n);
diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index cfcf97c021..fe2f6378b4 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -667,7 +667,8 @@ static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table,
 static inline int get_vlc_multi(GetBitContext *s, uint8_t *dst,
                                 const VLC_MULTI_ELEM *const Jtable,
                                 const VLCElem *const table,
-                                const int bits, const int max_depth)
+                                const int bits, const int max_depth,
+                                const int symbols_size)
 {
     dst[0] = get_vlc2(s, table, bits, max_depth);
     return 1;
diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 3f6348b531..4f30493626 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -124,7 +124,7 @@ static void magicyuv_median_pred16(uint16_t *dst, const uint16_t *src1,
     x = 0; \
     for (; CACHED_BITSTREAM_READER && x < width-c && get_bits_left(&gb) > 0;) {\
         ret = get_vlc_multi(&gb, (uint8_t *)dst + x * b, multi, \
-                            vlc, vlc_bits, 3); \
+                            vlc, vlc_bits, 3, b); \
         if (ret <= 0) \
             return AVERROR_INVALIDDATA; \
         x += ret; \
diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index ce5d00f7af..0c2e67e282 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -120,7 +120,7 @@ static int build_huff(UtvideoContext *c, const uint8_t *src, VLC *vlc,
     i = 0; \
     for (; CACHED_BITSTREAM_READER && i < width-end && get_bits_left(&gb) > 0;) {\
         ret = get_vlc_multi(&gb, (uint8_t *)buf + i * b, multi.table, \
-                            vlc.table, VLC_BITS, 3); \
+                            vlc.table, VLC_BITS, 3, b); \
         if (ret > 0) \
             i += ret; \
         if (ret <= 0) \
diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 78510e30d6..e01cc41689 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -499,7 +499,10 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC *single,
     for (int j = 0; j < 1<<numbits; j++) {
         table[j].len = single->table[j].len;
         table[j].num = single->table[j].len > 0 ? 1 : 0;
-        AV_WN16(table[j].val, single->table[j].sym);
+        if (is16bit)
+            AV_WN16(table[j].val, single->table[j].sym);
+        else
+            table[j].val[0] = single->table[j].sym;
     }
 
     add_level(table, is16bit, nb_codes, numbits, buf,
-- 
2.40.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2024-03-30  3:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29  3:23 [FFmpeg-devel] [PATCH 1/5] avcodec/ppc/hpeldsp_altivec: Fix left-shift of negative number Andreas Rheinhardt
2024-03-29  3:24 ` [FFmpeg-devel] [PATCH 2/5] fate/ffmpeg: Explicitly set pix fmt for sub2video tests Andreas Rheinhardt
2024-03-29 14:28   ` Sean McGovern
2024-03-29 14:45     ` Andreas Rheinhardt
2024-03-29  3:24 ` [FFmpeg-devel] [PATCH 3/5] avcodec/pngdsp: Fix unaligned accesses, effective type violations Andreas Rheinhardt
2024-03-29  3:24 ` [FFmpeg-devel] [PATCH 4/5] avfilter/vf_spp: Fix left-shift of negative value Andreas Rheinhardt
2024-03-29  3:24 ` [FFmpeg-devel] [PATCH 5/5] avcodec/huffyuvencdsp: Fix load of misaligned values Andreas Rheinhardt
2024-03-29 16:45 ` [FFmpeg-devel] [PATCH 6/6] fate/image: Fix EXR tests on big endian Andreas Rheinhardt
2024-03-30 18:28   ` Sean McGovern
2024-03-29 18:07 ` [FFmpeg-devel] [PATCH 7/7] fate/video: Only use bitexact IDCT in avid meridian Andreas Rheinhardt
2024-03-29 18:11 ` [FFmpeg-devel] [PATCH 8/8] fate/filter-video: Always use little endian pixel format Andreas Rheinhardt
2024-03-29 18:26 ` [FFmpeg-devel] [PATCH 9/9] fate/filter-video: Insert scale, format filters in filter-yadif tests Andreas Rheinhardt
2024-03-29 18:45 ` [FFmpeg-devel] [PATCH v2 9/9] fate/filter-video: Insert scale, format filters in filter-yadif, bwdif10 Andreas Rheinhardt
2024-03-30  3:15 ` [FFmpeg-devel] [PATCH 10/12] fate/fits: Fix tests on BE Andreas Rheinhardt
2024-03-30  3:15 ` Andreas Rheinhardt [this message]
2024-03-30  3:15 ` [FFmpeg-devel] [PATCH 12/12] avcodec/vlc: Use union of uint8_t and uint16_t in VLC_MULTI_ELEM Andreas Rheinhardt
2024-03-30  3:39 ` [FFmpeg-devel] [PATCH v2 " Andreas Rheinhardt
2024-04-01 18:41 ` [FFmpeg-devel] [PATCH 1/5] avcodec/ppc/hpeldsp_altivec: Fix left-shift of negative number Andreas Rheinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=GV1P250MB0737F1256A349CF58A18D4F58F392@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git