| Message ID | 20181020103540.22452-1-cus@passwd.hu |
|---|---|
| State | Accepted |
| Commit | b02490a497009064b7f192802aa246aa0b6a4dad |
| Headers |
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org> X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4FE9B44820A for <patchwork@ffaux-bg.ffmpeg.org>; Sat, 20 Oct 2018 13:35:43 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A2BAB68A6D9; Sat, 20 Oct 2018 13:35:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CCA0468A5BD for <ffmpeg-devel@ffmpeg.org>; Sat, 20 Oct 2018 13:35:18 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 27B07E16E8; Sat, 20 Oct 2018 12:35:45 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Eu8nolNG0iqO; Sat, 20 Oct 2018 12:35:44 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C3259E16C2; Sat, 20 Oct 2018 12:35:43 +0200 (CEST) From: Marton Balint <cus@passwd.hu> To: ffmpeg-devel@ffmpeg.org Date: Sat, 20 Oct 2018 12:35:40 +0200 Message-Id: <20181020103540.22452-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 Subject: [FFmpeg-devel] [PATCH] avcodec/libx264: remove FF_CODEC_CAP_INIT_THREADSAFE flag X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org> List-Unsubscribe: <http://ffmpeg.org/mailman/options/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe> List-Archive: <http://ffmpeg.org/pipermail/ffmpeg-devel/> List-Post: <mailto:ffmpeg-devel@ffmpeg.org> List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help> List-Subscribe: <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe> Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: Marton Balint <cus@passwd.hu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> |
Commit Message
Marton Balint
Oct. 20, 2018, 10:35 a.m. UTC
Libx264 uses strtok which is not thread safe. Strtok is used in
x264_param_default_preset in param_apply_tune in x264/common/base.c.
Therefore the flag must be removed.
Fixes ticket #7446.
Signed-off-by: Marton Balint <cus@passwd.hu>
---
libavcodec/libx264.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
Comments
On Sat, Oct 20, 2018 at 12:35 PM Marton Balint <cus@passwd.hu> wrote: > > Libx264 uses strtok which is not thread safe. Strtok is used in > x264_param_default_preset in param_apply_tune in x264/common/base.c. > Therefore the flag must be removed. > > Fixes ticket #7446. > > Signed-off-by: Marton Balint <cus@passwd.hu> > --- > libavcodec/libx264.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c > index 54e6703d73..d6367bf557 100644 > --- a/libavcodec/libx264.c > +++ b/libavcodec/libx264.c > @@ -1063,8 +1063,7 @@ AVCodec ff_libx264_encoder = { > .priv_class = &x264_class, > .defaults = x264_defaults, > .init_static_data = X264_init_static, > - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | > - FF_CODEC_CAP_INIT_CLEANUP, > + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, > .wrapper_name = "libx264", > }; > #endif > @@ -1115,8 +1114,7 @@ AVCodec ff_libx262_encoder = { > .priv_class = &X262_class, > .defaults = x264_defaults, > .pix_fmts = pix_fmts_8bit, > - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | > - FF_CODEC_CAP_INIT_CLEANUP, > + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, > .wrapper_name = "libx264", > }; > #endif > -- > 2.16.4 > Was this ever reported to x264? Theoretically some other library or another part of a calling application could still use strtok and break it. - Hendrik
On Sat, 20 Oct 2018, Hendrik Leppkes wrote: > On Sat, Oct 20, 2018 at 12:35 PM Marton Balint <cus@passwd.hu> wrote: >> >> Libx264 uses strtok which is not thread safe. Strtok is used in >> x264_param_default_preset in param_apply_tune in x264/common/base.c. >> Therefore the flag must be removed. >> >> Fixes ticket #7446. >> >> Signed-off-by: Marton Balint <cus@passwd.hu> >> --- >> libavcodec/libx264.c | 6 ++---- >> 1 file changed, 2 insertions(+), 4 deletions(-) >> >> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c >> index 54e6703d73..d6367bf557 100644 >> --- a/libavcodec/libx264.c >> +++ b/libavcodec/libx264.c >> @@ -1063,8 +1063,7 @@ AVCodec ff_libx264_encoder = { >> .priv_class = &x264_class, >> .defaults = x264_defaults, >> .init_static_data = X264_init_static, >> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | >> - FF_CODEC_CAP_INIT_CLEANUP, >> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, >> .wrapper_name = "libx264", >> }; >> #endif >> @@ -1115,8 +1114,7 @@ AVCodec ff_libx262_encoder = { >> .priv_class = &X262_class, >> .defaults = x264_defaults, >> .pix_fmts = pix_fmts_8bit, >> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | >> - FF_CODEC_CAP_INIT_CLEANUP, >> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, >> .wrapper_name = "libx264", >> }; >> #endif >> -- >> 2.16.4 >> > > Was this ever reported to x264? Not by me. > Theoretically some other library or another part of a calling > application could still use strtok and break it. I agree, this should be fixed in x264 as well, but until then it seems harmless to remove the flag. Regards, Marton
On Sat, Oct 20, 2018 at 12:30 PM Marton Balint <cus@passwd.hu> wrote: > > > On Sat, 20 Oct 2018, Hendrik Leppkes wrote: > > > On Sat, Oct 20, 2018 at 12:35 PM Marton Balint <cus@passwd.hu> wrote: > >> > >> Libx264 uses strtok which is not thread safe. Strtok is used in > >> x264_param_default_preset in param_apply_tune in x264/common/base.c. > >> Therefore the flag must be removed. > >> > >> Fixes ticket #7446. > >> > >> Signed-off-by: Marton Balint <cus@passwd.hu> > >> --- > >> libavcodec/libx264.c | 6 ++---- > >> 1 file changed, 2 insertions(+), 4 deletions(-) > >> > >> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c > >> index 54e6703d73..d6367bf557 100644 > >> --- a/libavcodec/libx264.c > >> +++ b/libavcodec/libx264.c > >> @@ -1063,8 +1063,7 @@ AVCodec ff_libx264_encoder = { > >> .priv_class = &x264_class, > >> .defaults = x264_defaults, > >> .init_static_data = X264_init_static, > >> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | > >> - FF_CODEC_CAP_INIT_CLEANUP, > >> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, > >> .wrapper_name = "libx264", > >> }; > >> #endif > >> @@ -1115,8 +1114,7 @@ AVCodec ff_libx262_encoder = { > >> .priv_class = &X262_class, > >> .defaults = x264_defaults, > >> .pix_fmts = pix_fmts_8bit, > >> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | > >> - FF_CODEC_CAP_INIT_CLEANUP, > >> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, > >> .wrapper_name = "libx264", > >> }; > >> #endif > >> -- > >> 2.16.4 > >> > > > > Was this ever reported to x264? > > Not by me. > > > Theoretically some other library or another part of a calling > > application could still use strtok and break it. > > I agree, this should be fixed in x264 as well, but until then it > seems harmless to remove the flag. > this could potentially break a couple of use cases where it "happens to work" (especially those that rely on the aforementioned abaa1226) rather that dropping the flag entirely, why not fixing x264 first, bump its version, and apply the flag conditionally on that?
On Sat, 20 Oct 2018, Vittorio Giovara wrote: > On Sat, Oct 20, 2018 at 12:30 PM Marton Balint <cus@passwd.hu> wrote: > >> >> >> On Sat, 20 Oct 2018, Hendrik Leppkes wrote: >> >> > On Sat, Oct 20, 2018 at 12:35 PM Marton Balint <cus@passwd.hu> wrote: >> >> >> >> Libx264 uses strtok which is not thread safe. Strtok is used in >> >> x264_param_default_preset in param_apply_tune in x264/common/base.c. >> >> Therefore the flag must be removed. >> >> >> >> Fixes ticket #7446. >> >> >> >> Signed-off-by: Marton Balint <cus@passwd.hu> >> >> --- >> >> libavcodec/libx264.c | 6 ++---- >> >> 1 file changed, 2 insertions(+), 4 deletions(-) >> >> >> >> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c >> >> index 54e6703d73..d6367bf557 100644 >> >> --- a/libavcodec/libx264.c >> >> +++ b/libavcodec/libx264.c >> >> @@ -1063,8 +1063,7 @@ AVCodec ff_libx264_encoder = { >> >> .priv_class = &x264_class, >> >> .defaults = x264_defaults, >> >> .init_static_data = X264_init_static, >> >> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | >> >> - FF_CODEC_CAP_INIT_CLEANUP, >> >> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, >> >> .wrapper_name = "libx264", >> >> }; >> >> #endif >> >> @@ -1115,8 +1114,7 @@ AVCodec ff_libx262_encoder = { >> >> .priv_class = &X262_class, >> >> .defaults = x264_defaults, >> >> .pix_fmts = pix_fmts_8bit, >> >> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | >> >> - FF_CODEC_CAP_INIT_CLEANUP, >> >> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, >> >> .wrapper_name = "libx264", >> >> }; >> >> #endif >> >> -- >> >> 2.16.4 >> >> >> > >> > Was this ever reported to x264? >> >> Not by me. >> >> > Theoretically some other library or another part of a calling >> > application could still use strtok and break it. >> >> I agree, this should be fixed in x264 as well, but until then it >> seems harmless to remove the flag. >> > > this could potentially break a couple of use cases where it "happens to > work" (especially those that rely on the aforementioned abaa1226) > rather that dropping the flag entirely, why not fixing x264 first, bump its > version, and apply the flag conditionally on that? Fine by me, if someone could pick this up on the x264 side that would be great. Thanks, Marton
On Sat, Oct 20, 2018 at 4:50 PM Vittorio Giovara <vittorio.giovara@gmail.com> wrote: > > On Sat, Oct 20, 2018 at 12:30 PM Marton Balint <cus@passwd.hu> wrote: > > > > > > > On Sat, 20 Oct 2018, Hendrik Leppkes wrote: > > > > > On Sat, Oct 20, 2018 at 12:35 PM Marton Balint <cus@passwd.hu> wrote: > > >> > > >> Libx264 uses strtok which is not thread safe. Strtok is used in > > >> x264_param_default_preset in param_apply_tune in x264/common/base.c. > > >> Therefore the flag must be removed. > > >> > > >> Fixes ticket #7446. > > >> > > >> Signed-off-by: Marton Balint <cus@passwd.hu> > > >> --- > > >> libavcodec/libx264.c | 6 ++---- > > >> 1 file changed, 2 insertions(+), 4 deletions(-) > > >> > > >> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c > > >> index 54e6703d73..d6367bf557 100644 > > >> --- a/libavcodec/libx264.c > > >> +++ b/libavcodec/libx264.c > > >> @@ -1063,8 +1063,7 @@ AVCodec ff_libx264_encoder = { > > >> .priv_class = &x264_class, > > >> .defaults = x264_defaults, > > >> .init_static_data = X264_init_static, > > >> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | > > >> - FF_CODEC_CAP_INIT_CLEANUP, > > >> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, > > >> .wrapper_name = "libx264", > > >> }; > > >> #endif > > >> @@ -1115,8 +1114,7 @@ AVCodec ff_libx262_encoder = { > > >> .priv_class = &X262_class, > > >> .defaults = x264_defaults, > > >> .pix_fmts = pix_fmts_8bit, > > >> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | > > >> - FF_CODEC_CAP_INIT_CLEANUP, > > >> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, > > >> .wrapper_name = "libx264", > > >> }; > > >> #endif > > >> -- > > >> 2.16.4 > > >> > > > > > > Was this ever reported to x264? > > > > Not by me. > > > > > Theoretically some other library or another part of a calling > > > application could still use strtok and break it. > > > > I agree, this should be fixed in x264 as well, but until then it > > seems harmless to remove the flag. > > > > this could potentially break a couple of use cases where it "happens to > work" (especially those that rely on the aforementioned abaa1226) > rather that dropping the flag entirely, why not fixing x264 first, bump its > version, and apply the flag conditionally on that? What exactly would this break? avcodec should just do the right thing. It would just be slower. The flag can be re-introduced if a fixed version is released. - Hendrik
Fixed in x264-sandbox. All uses of plain strtok() will be removed from x264 in the next push. I though all of the strtok() uses in x264 had already been converted to strtok_r() but apparently that wasn't the case. Sorry about that.
On Sun, 21 Oct 2018, Henrik Gramner wrote: > Fixed in x264-sandbox. All uses of plain strtok() will be removed from > x264 in the next push. Great, thanks! Can you give us an X264_BUILD number from which this will be fixed? Thanks, Marton
2018-10-22 2:25 GMT+02:00, Marton Balint <cus@passwd.hu>: > > On Sun, 21 Oct 2018, Henrik Gramner wrote: > >> Fixed in x264-sandbox. All uses of plain strtok() will be >> removed from x264 in the next push. > > Great, thanks! Can you give us an X264_BUILD number from > which this will be fixed? Could you push your patch in the meantime? Thank you, Carl Eugen
Hi, On 21/10/2018 15:07, Henrik Gramner wrote: > Fixed in x264-sandbox. All uses of plain strtok() will be removed from > x264 in the next push. > > I though all of the strtok() uses in x264 had already been converted > to strtok_r() but apparently that wasn't the case. Sorry about that. I'd like to point out that this patch or some variant may be required anyway. libx264 only uses strtok_r or strtok_s if available on the platform. See: https://git.videolan.org/?p=x264.git;a=blob;f=common/osdep.h;h=715ef8a00c01ad5a94de2b29a422429b9b1f0a53;hb=HEAD#l75 The real fix is to bundle a strtok_r implementation, or to just outright require strtok_r/strtok_s. Sad, I know. What platforms that x264 supports don't have it anyway? - Derek
On Tue, Oct 23, 2018 at 3:22 PM Derek Buitenhuis <derek.buitenhuis@gmail.com> wrote: > I'd like to point out that this patch or some variant may be required anyway. > > libx264 only uses strtok_r or strtok_s if available on the platform. > > See: https://git.videolan.org/?p=x264.git;a=blob;f=common/osdep.h;h=715ef8a00c01ad5a94de2b29a422429b9b1f0a53;hb=HEAD#l75 > > The real fix is to bundle a strtok_r implementation, or to just outright > require strtok_r/strtok_s. Sad, I know. > > What platforms that x264 supports don't have it anyway? Honestly no idea, probably something obscure.
On Tue, 23 Oct 2018, Henrik Gramner wrote: > On Tue, Oct 23, 2018 at 3:22 PM Derek Buitenhuis > <derek.buitenhuis@gmail.com> wrote: >> I'd like to point out that this patch or some variant may be required anyway. >> >> libx264 only uses strtok_r or strtok_s if available on the platform. >> >> See: https://git.videolan.org/?p=x264.git;a=blob;f=common/osdep.h;h=715ef8a00c01ad5a94de2b29a422429b9b1f0a53;hb=HEAD#l75 >> >> The real fix is to bundle a strtok_r implementation, or to just outright >> require strtok_r/strtok_s. Sad, I know. >> >> What platforms that x264 supports don't have it anyway? > > Honestly no idea, probably something obscure. Well, then maybe x264 configure should simply fail for those. I pushed the patch, once the strtok fix is merged to stable and we know the build number, the flag can be re-introduced with an #if. Regards, Marton
On 10/24/2018 6:43 PM, Marton Balint wrote: > > > On Tue, 23 Oct 2018, Henrik Gramner wrote: > >> On Tue, Oct 23, 2018 at 3:22 PM Derek Buitenhuis >> <derek.buitenhuis@gmail.com> wrote: >>> I'd like to point out that this patch or some variant may be required >>> anyway. >>> >>> libx264 only uses strtok_r or strtok_s if available on the platform. >>> >>> See: >>> https://git.videolan.org/?p=x264.git;a=blob;f=common/osdep.h;h=715ef8a00c01ad5a94de2b29a422429b9b1f0a53;hb=HEAD#l75 >>> >>> >>> The real fix is to bundle a strtok_r implementation, or to just outright >>> require strtok_r/strtok_s. Sad, I know. >>> >>> What platforms that x264 supports don't have it anyway? >> >> Honestly no idea, probably something obscure. > > Well, then maybe x264 configure should simply fail for those. > > I pushed the patch, once the strtok fix is merged to stable and we know > the build number, the flag can be re-introduced with an #if. > > Regards, > Marton This should be backported to supported branches, or at least 2.8, 3.2, 3.4 and 4.0
On Wed, 24 Oct 2018, James Almer wrote: > On 10/24/2018 6:43 PM, Marton Balint wrote: >> >> >> On Tue, 23 Oct 2018, Henrik Gramner wrote: >> >>> On Tue, Oct 23, 2018 at 3:22 PM Derek Buitenhuis >>> <derek.buitenhuis@gmail.com> wrote: >>>> I'd like to point out that this patch or some variant may be required >>>> anyway. >>>> >>>> libx264 only uses strtok_r or strtok_s if available on the platform. >>>> >>>> See: >>>> https://git.videolan.org/?p=x264.git;a=blob;f=common/osdep.h;h=715ef8a00c01ad5a94de2b29a422429b9b1f0a53;hb=HEAD#l75 >>>> >>>> >>>> The real fix is to bundle a strtok_r implementation, or to just outright >>>> require strtok_r/strtok_s. Sad, I know. >>>> >>>> What platforms that x264 supports don't have it anyway? >>> >>> Honestly no idea, probably something obscure. >> >> Well, then maybe x264 configure should simply fail for those. >> >> I pushed the patch, once the strtok fix is merged to stable and we know >> the build number, the flag can be re-introduced with an #if. >> >> Regards, >> Marton > > This should be backported to supported branches, or at least 2.8, 3.2, > 3.4 and 4.0 I did it for 4.0, I leave the rest for others. Regards, Marton
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 54e6703d73..d6367bf557 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -1063,8 +1063,7 @@ AVCodec ff_libx264_encoder = { .priv_class = &x264_class, .defaults = x264_defaults, .init_static_data = X264_init_static, - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | - FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, .wrapper_name = "libx264", }; #endif @@ -1115,8 +1114,7 @@ AVCodec ff_libx262_encoder = { .priv_class = &X262_class, .defaults = x264_defaults, .pix_fmts = pix_fmts_8bit, - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | - FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, .wrapper_name = "libx264", }; #endif