Message ID | 20240617203301.25534-1-cus@passwd.hu |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel] avutil/timestamp: avoid possible FPE when 0 is passed to av_ts_make_time_string2() | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | success | Make finished |
yinshiyou/make_fate_loongarch64 | success | Make fate finished |
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
Le 17 juin 2024 22:33:01 GMT+02:00, Marton Balint <cus@passwd.hu> a écrit : >Signed-off-by: Marton Balint <cus@passwd.hu> >--- > libavutil/timestamp.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >diff --git a/libavutil/timestamp.c b/libavutil/timestamp.c >index 2a3e3012a4..6c231a517d 100644 >--- a/libavutil/timestamp.c >+++ b/libavutil/timestamp.c >@@ -24,7 +24,7 @@ char *av_ts_make_time_string2(char *buf, int64_t ts, AVRational tb) > snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS"); > } else { > double val = av_q2d(tb) * ts; >- double log = floor(log10(fabs(val))); >+ double log = (fpclassify(val) == FP_ZERO ? -INFINITY : floor(log10(fabs(val)))); > int precision = (isfinite(log) && log < 0) ? -log + 5 : 6; Can the log be infinite anymore? > int last = snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.*f", precision, val); > last = FFMIN(last, AV_TS_MAX_STRING_SIZE - 1) - 1;
On Tue, 18 Jun 2024, Rémi Denis-Courmont wrote: > > > Le 17 juin 2024 22:33:01 GMT+02:00, Marton Balint <cus@passwd.hu> a écrit : >> Signed-off-by: Marton Balint <cus@passwd.hu> >> --- >> libavutil/timestamp.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/libavutil/timestamp.c b/libavutil/timestamp.c >> index 2a3e3012a4..6c231a517d 100644 >> --- a/libavutil/timestamp.c >> +++ b/libavutil/timestamp.c >> @@ -24,7 +24,7 @@ char *av_ts_make_time_string2(char *buf, int64_t ts, AVRational tb) >> snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS"); >> } else { >> double val = av_q2d(tb) * ts; >> - double log = floor(log10(fabs(val))); >> + double log = (fpclassify(val) == FP_ZERO ? -INFINITY : floor(log10(fabs(val)))); >> int precision = (isfinite(log) && log < 0) ? -log + 5 : 6; > > Can the log be infinite anymore? Yes, in case of zero value we explicitly set it to -INFINITY, but implicit infinity or NaN is also possible, because av_q2d can return both. Regards, Marton
diff --git a/libavutil/timestamp.c b/libavutil/timestamp.c index 2a3e3012a4..6c231a517d 100644 --- a/libavutil/timestamp.c +++ b/libavutil/timestamp.c @@ -24,7 +24,7 @@ char *av_ts_make_time_string2(char *buf, int64_t ts, AVRational tb) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS"); } else { double val = av_q2d(tb) * ts; - double log = floor(log10(fabs(val))); + double log = (fpclassify(val) == FP_ZERO ? -INFINITY : floor(log10(fabs(val)))); int precision = (isfinite(log) && log < 0) ? -log + 5 : 6; int last = snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.*f", precision, val); last = FFMIN(last, AV_TS_MAX_STRING_SIZE - 1) - 1;
Signed-off-by: Marton Balint <cus@passwd.hu> --- libavutil/timestamp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)