From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH] swscale/utils: Fix potential race when initializing xyz tables Date: Sat, 24 May 2025 16:05:00 +0200 Message-ID: <AS8P250MB07448797D430D5E65A6805588F9BA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) [-- Attachment #1: Type: text/plain, Size: 27 bytes --] Patch attached. - Andreas [-- Attachment #2: 0001-swscale-utils-Fix-potential-race-when-initializing-x.patch --] [-- Type: text/x-patch, Size: 3535 bytes --] From 418fd788de2902641e6d4693137a620cab413c37 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Sat, 24 May 2025 16:02:04 +0200 Subject: [PATCH] swscale/utils: Fix potential race when initializing xyz tables Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libswscale/utils.c | 53 +++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/libswscale/utils.c b/libswscale/utils.c index f659e22fdc..94a47ea5d0 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -692,13 +692,35 @@ static void fill_rgb2yuv_table(SwsInternal *c, const int table[4], int dstRange) AV_WL16(p + 16*4 + 2*i, map[i] >= 0 ? c->input_rgb2yuv_table[map[i]] : 0); } -static int fill_xyztables(SwsInternal *c) +#if CONFIG_SMALL +static void init_xyz_tables(uint16_t xyzgamma_tab[4096], uint16_t xyzgammainv_tab[65536], + uint16_t rgbgamma_tab[65536], uint16_t rgbgammainv_tab[4096]) +#else +static uint16_t xyzgamma_tab[4096], rgbgammainv_tab[4096]; +static uint16_t rgbgamma_tab[65536], xyzgammainv_tab[65536]; +static av_cold void init_xyz_tables(void) +#endif { - int i; - double xyzgamma = XYZ_GAMMA; - double rgbgamma = 1.0 / RGB_GAMMA; + double xyzgamma = XYZ_GAMMA; + double rgbgamma = 1.0 / RGB_GAMMA; double xyzgammainv = 1.0 / XYZ_GAMMA; double rgbgammainv = RGB_GAMMA; + + /* set input gamma vectors */ + for (int i = 0; i < 4096; i++) { + xyzgamma_tab[i] = lrint(pow(i / 4095.0, xyzgamma) * 65535.0); + rgbgammainv_tab[i] = lrint(pow(i / 4095.0, rgbgammainv) * 65535.0); + } + + /* set output gamma vectors */ + for (int i = 0; i < 65536; i++) { + rgbgamma_tab[i] = lrint(pow(i / 65535.0, rgbgamma) * 4095.0); + xyzgammainv_tab[i] = lrint(pow(i / 65535.0, xyzgammainv) * 4095.0); + } +} + +static int fill_xyztables(SwsInternal *c) +{ static const int16_t xyz2rgb_matrix[3][4] = { {13270, -6295, -2041}, {-3969, 7682, 170}, @@ -707,10 +729,7 @@ static int fill_xyztables(SwsInternal *c) {1689, 1464, 739}, { 871, 2929, 296}, { 79, 488, 3891} }; -#if !CONFIG_SMALL - static uint16_t xyzgamma_tab[4096], rgbgammainv_tab[4096]; - static uint16_t rgbgamma_tab[65536], xyzgammainv_tab[65536]; -#endif + if (c->xyzgamma) return 0; @@ -724,26 +743,16 @@ static int fill_xyztables(SwsInternal *c) c->rgbgammainv = c->xyzgamma + 4096; c->rgbgamma = c->rgbgammainv + 4096; c->xyzgammainv = c->rgbgamma + 65536; + init_xyz_tables(c->xyzgamma, c->xyzgammainv, c->rgbgamma, c->rgbgammainv); #else c->xyzgamma = xyzgamma_tab; c->rgbgamma = rgbgamma_tab; c->xyzgammainv = xyzgammainv_tab; c->rgbgammainv = rgbgammainv_tab; - if (xyzgamma_tab[4095]) - return 0; -#endif - /* set input gamma vectors */ - for (i = 0; i < 4096; i++) { - c->xyzgamma[i] = lrint(pow(i / 4095.0, xyzgamma) * 65535.0); - c->rgbgammainv[i] = lrint(pow(i / 4095.0, rgbgammainv) * 65535.0); - } - - /* set output gamma vectors */ - for (i = 0; i < 65536; i++) { - c->rgbgamma[i] = lrint(pow(i / 65535.0, rgbgamma) * 4095.0); - c->xyzgammainv[i] = lrint(pow(i / 65535.0, xyzgammainv) * 4095.0); - } + static AVOnce xyz_init_static_once = AV_ONCE_INIT; + ff_thread_once(&xyz_init_static_once, init_xyz_tables); +#endif return 0; } -- 2.45.2 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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".
next reply other threads:[~2025-05-24 14:05 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-05-24 14:05 Andreas Rheinhardt [this message] 2025-05-26 14:40 ` 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=AS8P250MB07448797D430D5E65A6805588F9BA@AS8P250MB0744.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