[FFmpeg-devel] avformat/subtitles: ignore extra '\r' at line endings

Submitted by Paul B Mahol on April 25, 2019, 9:22 p.m.

Details

Message ID 20190425212247.11287-1-onemda@gmail.com
State New
Headers show

Commit Message

Paul B Mahol April 25, 2019, 9:22 p.m.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavformat/microdvddec.c | 2 ++
 libavformat/subtitles.c   | 2 +-
 libavformat/subtitles.h   | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

Comments

Clément Bœsch April 27, 2019, 10:05 a.m.
On Thu, Apr 25, 2019 at 11:22:47PM +0200, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavformat/microdvddec.c | 2 ++
>  libavformat/subtitles.c   | 2 +-
>  libavformat/subtitles.h   | 2 +-
>  3 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/microdvddec.c b/libavformat/microdvddec.c
> index ef6bcfbc73..598093309c 100644
> --- a/libavformat/microdvddec.c
> +++ b/libavformat/microdvddec.c
> @@ -130,6 +130,8 @@ static int microdvd_read_header(AVFormatContext *s)
>          continue;                                           \
>      }                                                       \
>      p++
> +        if (!*p)
> +            continue;
>          SKIP_FRAME_ID;
>          SKIP_FRAME_ID;
>          if (!*p)

This looks unrelated and should probably be much earlier (just after `p =
line`?)

> diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
> index 93c9ef05cf..659c99d1cf 100644
> --- a/libavformat/subtitles.c
> +++ b/libavformat/subtitles.c
> @@ -417,7 +417,7 @@ ptrdiff_t ff_subtitles_read_line(FFTextReader *tr, char *buf, size_t size)
>          buf[cur++] = c;
>          buf[cur] = '\0';
>      }
> -    if (ff_text_peek_r8(tr) == '\r')
> +    while (ff_text_peek_r8(tr) == '\r')
>          ff_text_r8(tr);
>      if (ff_text_peek_r8(tr) == '\n')
>          ff_text_r8(tr);
> diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h
> index ca78db224d..6b418e3621 100644
> --- a/libavformat/subtitles.h
> +++ b/libavformat/subtitles.h
> @@ -188,7 +188,7 @@ static av_always_inline int ff_subtitles_next_line(const char *ptr)
>  {
>      int n = strcspn(ptr, "\r\n");
>      ptr += n;
> -    if (*ptr == '\r') {
> +    while (*ptr == '\r') {
>          ptr++;
>          n++;

Rest should be fine if it passes FATE.
Paul B Mahol April 27, 2019, 10:42 a.m.
On 4/27/19, Clément Bœsch <u@pkh.me> wrote:
> On Thu, Apr 25, 2019 at 11:22:47PM +0200, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> ---
>>  libavformat/microdvddec.c | 2 ++
>>  libavformat/subtitles.c   | 2 +-
>>  libavformat/subtitles.h   | 2 +-
>>  3 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavformat/microdvddec.c b/libavformat/microdvddec.c
>> index ef6bcfbc73..598093309c 100644
>> --- a/libavformat/microdvddec.c
>> +++ b/libavformat/microdvddec.c
>> @@ -130,6 +130,8 @@ static int microdvd_read_header(AVFormatContext *s)
>>          continue;                                           \
>>      }                                                       \
>>      p++
>> +        if (!*p)
>> +            continue;
>>          SKIP_FRAME_ID;
>>          SKIP_FRAME_ID;
>>          if (!*p)
>
> This looks unrelated and should probably be much earlier (just after `p =
> line`?)

Agreed. This removes warnings about invalid events.
Will push separately.

>
>> diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
>> index 93c9ef05cf..659c99d1cf 100644
>> --- a/libavformat/subtitles.c
>> +++ b/libavformat/subtitles.c
>> @@ -417,7 +417,7 @@ ptrdiff_t ff_subtitles_read_line(FFTextReader *tr,
>> char *buf, size_t size)
>>          buf[cur++] = c;
>>          buf[cur] = '\0';
>>      }
>> -    if (ff_text_peek_r8(tr) == '\r')
>> +    while (ff_text_peek_r8(tr) == '\r')
>>          ff_text_r8(tr);
>>      if (ff_text_peek_r8(tr) == '\n')
>>          ff_text_r8(tr);
>> diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h
>> index ca78db224d..6b418e3621 100644
>> --- a/libavformat/subtitles.h
>> +++ b/libavformat/subtitles.h
>> @@ -188,7 +188,7 @@ static av_always_inline int
>> ff_subtitles_next_line(const char *ptr)
>>  {
>>      int n = strcspn(ptr, "\r\n");
>>      ptr += n;
>> -    if (*ptr == '\r') {
>> +    while (*ptr == '\r') {
>>          ptr++;
>>          n++;
>
> Rest should be fine if it passes FATE.
>
> --
> Clément B.
>

Patch hide | download patch | download mbox

diff --git a/libavformat/microdvddec.c b/libavformat/microdvddec.c
index ef6bcfbc73..598093309c 100644
--- a/libavformat/microdvddec.c
+++ b/libavformat/microdvddec.c
@@ -130,6 +130,8 @@  static int microdvd_read_header(AVFormatContext *s)
         continue;                                           \
     }                                                       \
     p++
+        if (!*p)
+            continue;
         SKIP_FRAME_ID;
         SKIP_FRAME_ID;
         if (!*p)
diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
index 93c9ef05cf..659c99d1cf 100644
--- a/libavformat/subtitles.c
+++ b/libavformat/subtitles.c
@@ -417,7 +417,7 @@  ptrdiff_t ff_subtitles_read_line(FFTextReader *tr, char *buf, size_t size)
         buf[cur++] = c;
         buf[cur] = '\0';
     }
-    if (ff_text_peek_r8(tr) == '\r')
+    while (ff_text_peek_r8(tr) == '\r')
         ff_text_r8(tr);
     if (ff_text_peek_r8(tr) == '\n')
         ff_text_r8(tr);
diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h
index ca78db224d..6b418e3621 100644
--- a/libavformat/subtitles.h
+++ b/libavformat/subtitles.h
@@ -188,7 +188,7 @@  static av_always_inline int ff_subtitles_next_line(const char *ptr)
 {
     int n = strcspn(ptr, "\r\n");
     ptr += n;
-    if (*ptr == '\r') {
+    while (*ptr == '\r') {
         ptr++;
         n++;
     }