Compare commits

...

5 Commits

Author SHA1 Message Date
Martin Storsjö 3cc1dc3358 swscale: Remove the unused ff_sws_pixel_type_to_uint
This function uses ff_sws_pixel_type_size to switch on the
size of the provided type. However, ff_sws_pixel_type_size returns
a size in bytes (from sizeof()), not a size in bits. Therefore,
this would previously never return the right thing but always
hit the av_unreachable() below.

As the function is entirely unused, just remove it.

This fixes compilation with MSVC 2026 18.0 when targeting ARM64,
which previously hit an internal compiler error [1].

[1] https://developercommunity.visualstudio.com/t/Internal-Compiler-Error-targeting-ARM64-/10962922
2025-11-21 21:07:34 +00:00
Andreas Rheinhardt 775b102182 avformat/oggenc: Schedule pagesize option for removal
Deprecated in 59220d559b.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-11-21 18:41:15 +00:00
James Almer 191f7e4869 tests/checkasm/sw_ops: fix signed integer related UB when shifting values
Fixes:
src/tests/checkasm/sw_ops.c:441:34: runtime error: shift exponent 32 is too large for 32-bit type 'int'
src/tests/checkasm/sw_ops.c:591:37: runtime error: shift exponent 32 is too large for 32-bit type 'int'

Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-21 18:40:58 +00:00
James Almer 06b3a20761 swscale/ops_tmpl_int: fix signed integer related UB when shifting values
Fixes:
src/libswscale/ops_tmpl_int.c:292:23: runtime error: left shift of 188 by 24 places cannot be represented in type 'int'
src/libswscale/ops_tmpl_int.c:290:23: runtime error: left shift of 158 by 24 places cannot be represented in type 'int'
src/libswscale/ops_tmpl_int.c:293:23: runtime error: left shift of 136 by 24 places cannot be represented in type 'int'
src/libswscale/ops_tmpl_int.c:291:23: runtime error: left shift of 160 by 24 places cannot be represented in type 'int'

Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-21 18:40:58 +00:00
James Almer 30d66be21a swscale/x86/ops: fix signed integer related UB in normalize_clear()
Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-21 18:40:58 +00:00
6 changed files with 19 additions and 30 deletions

View File

@ -76,7 +76,9 @@ typedef struct OGGPageList {
typedef struct OGGContext {
const AVClass *class;
OGGPageList *page_list;
#if LIBAVFORMAT_VERSION_MAJOR < 63
int pref_size; ///< preferred page size (0 => fill all segments)
#endif
int64_t pref_duration; ///< preferred page duration (0 => fill all segments)
int serial_offset;
} OGGContext;
@ -87,10 +89,12 @@ typedef struct OGGContext {
static const AVOption options[] = {
{ "serial_offset", "serial number offset",
OFFSET(serial_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, PARAM },
#if LIBAVFORMAT_VERSION_MAJOR < 63
{ "oggpagesize", "Set preferred Ogg page size.",
OFFSET(pref_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, MAX_PAGE_SIZE, PARAM},
{ "pagesize", "preferred page size in bytes (deprecated)",
OFFSET(pref_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_PAGE_SIZE, PARAM },
OFFSET(pref_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, MAX_PAGE_SIZE, PARAM | AV_OPT_FLAG_DEPRECATED },
{ "pagesize", "preferred page size in bytes",
OFFSET(pref_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_PAGE_SIZE, PARAM | AV_OPT_FLAG_DEPRECATED },
#endif
{ "page_duration", "preferred page duration, in microseconds",
OFFSET(pref_duration), AV_OPT_TYPE_INT64, { .i64 = 1000000 }, 0, INT64_MAX, PARAM },
{ NULL },
@ -262,8 +266,12 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
if (page->segments_count == 255) {
ogg_buffer_page(s, oggstream);
} else if (!header) {
#if LIBAVFORMAT_VERSION_MAJOR < 63
if ((ogg->pref_size > 0 && page->size >= ogg->pref_size) ||
(ogg->pref_duration > 0 && next - start >= ogg->pref_duration)) {
#else
if (ogg->pref_duration > 0 && next - start >= ogg->pref_duration) {
#endif
ogg_buffer_page(s, oggstream);
}
}
@ -477,9 +485,6 @@ static int ogg_init(AVFormatContext *s)
OGGStreamContext *oggstream = NULL;
int i, j;
if (ogg->pref_size)
av_log(s, AV_LOG_WARNING, "The pagesize option is deprecated\n");
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
unsigned serial_num = i + ogg->serial_offset;

View File

@ -93,21 +93,6 @@ bool ff_sws_pixel_type_is_int(SwsPixelType type)
return false;
}
SwsPixelType ff_sws_pixel_type_to_uint(SwsPixelType type)
{
if (!type)
return type;
switch (ff_sws_pixel_type_size(type)) {
case 8: return SWS_PIXEL_U8;
case 16: return SWS_PIXEL_U16;
case 32: return SWS_PIXEL_U32;
}
av_unreachable("Invalid pixel type!");
return SWS_PIXEL_NONE;
}
/* biased towards `a` */
static AVRational av_min_q(AVRational a, AVRational b)
{

View File

@ -39,7 +39,6 @@ typedef enum SwsPixelType {
const char *ff_sws_pixel_type_name(SwsPixelType type);
int ff_sws_pixel_type_size(SwsPixelType type) av_const;
bool ff_sws_pixel_type_is_int(SwsPixelType type) av_const;
SwsPixelType ff_sws_pixel_type_to_uint(SwsPixelType type) av_const;
typedef enum SwsOpType {
SWS_OP_INVALID = 0,

View File

@ -287,10 +287,10 @@ DECL_PATTERN(expand32)
SWS_LOOP
for (int i = 0; i < SWS_BLOCK_SIZE; i++) {
x32[i] = x[i] << 24 | x[i] << 16 | x[i] << 8 | x[i];
y32[i] = y[i] << 24 | y[i] << 16 | y[i] << 8 | y[i];
z32[i] = z[i] << 24 | z[i] << 16 | z[i] << 8 | z[i];
w32[i] = w[i] << 24 | w[i] << 16 | w[i] << 8 | w[i];
x32[i] = (uint32_t)x[i] << 24 | x[i] << 16 | x[i] << 8 | x[i];
y32[i] = (uint32_t)y[i] << 24 | y[i] << 16 | y[i] << 8 | y[i];
z32[i] = (uint32_t)z[i] << 24 | z[i] << 16 | z[i] << 8 | z[i];
w32[i] = (uint32_t)w[i] << 24 | w[i] << 16 | w[i] << 8 | w[i];
}
CONTINUE(u32block_t, x32, y32, z32, w32);

View File

@ -616,8 +616,8 @@ static void normalize_clear(SwsOp *op)
if (!op->c.q4[i].den)
continue;
switch (ff_sws_pixel_type_size(op->type)) {
case 1: c.u32 = 0x1010101 * priv.u8[i]; break;
case 2: c.u32 = priv.u16[i] << 16 | priv.u16[i]; break;
case 1: c.u32 = 0x1010101U * priv.u8[i]; break;
case 2: c.u32 = (uint32_t)priv.u16[i] << 16 | priv.u16[i]; break;
case 4: c.u32 = priv.u32[i]; break;
}

View File

@ -438,7 +438,7 @@ static AVRational rndq(SwsPixelType t)
{
const unsigned num = rnd();
if (ff_sws_pixel_type_is_int(t)) {
const unsigned mask = (1 << (ff_sws_pixel_type_size(t) * 8)) - 1;
const unsigned mask = UINT_MAX >> (32 - ff_sws_pixel_type_size(t) * 8);
return (AVRational) { num & mask, 1 };
} else {
const unsigned den = rnd();
@ -588,7 +588,7 @@ static void check_convert(void)
.convert.to = o,
});
} else if (isize > osize || !ff_sws_pixel_type_is_int(i)) {
uint32_t range = (1 << osize * 8) - 1;
uint32_t range = UINT32_MAX >> (32 - osize * 8);
CHECK_COMMON_RANGE(name, range, i, o, {
.op = SWS_OP_CONVERT,
.type = i,