Commit cd8fd586 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

araw: filter out non-finite floating point samples

The input is not neessarily trusted. Better safe than sorry.
parent eee1dd00
...@@ -24,6 +24,7 @@ libaes3_plugin_la_SOURCES = codec/aes3.c ...@@ -24,6 +24,7 @@ libaes3_plugin_la_SOURCES = codec/aes3.c
codec_LTLIBRARIES += libaes3_plugin.la codec_LTLIBRARIES += libaes3_plugin.la
libaraw_plugin_la_SOURCES = codec/araw.c libaraw_plugin_la_SOURCES = codec/araw.c
libaraw_plugin_la_LIBADD = $(LIBM)
codec_LTLIBRARIES += libaraw_plugin.la codec_LTLIBRARIES += libaraw_plugin.la
libdts_plugin_la_SOURCES = codec/dts.c codec/dts_header.c codec/dts_header.h libdts_plugin_la_SOURCES = codec/dts.c codec/dts_header.c codec/dts_header.h
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include <math.h>
#include <assert.h> #include <assert.h>
#include <vlc_common.h> #include <vlc_common.h>
...@@ -96,7 +97,9 @@ static void S24L32Decode( void *, const uint8_t *, unsigned ); ...@@ -96,7 +97,9 @@ static void S24L32Decode( void *, const uint8_t *, unsigned );
static void U32BDecode( void *, const uint8_t *, unsigned ); static void U32BDecode( void *, const uint8_t *, unsigned );
static void U32LDecode( void *, const uint8_t *, unsigned ); static void U32LDecode( void *, const uint8_t *, unsigned );
static void S32IDecode( void *, const uint8_t *, unsigned ); static void S32IDecode( void *, const uint8_t *, unsigned );
static void F32NDecode( void *, const uint8_t *, unsigned );
static void F32IDecode( void *, const uint8_t *, unsigned ); static void F32IDecode( void *, const uint8_t *, unsigned );
static void F64NDecode( void *, const uint8_t *, unsigned );
static void F64IDecode( void *, const uint8_t *, unsigned ); static void F64IDecode( void *, const uint8_t *, unsigned );
static void DAT12Decode( void *, const uint8_t *, unsigned ); static void DAT12Decode( void *, const uint8_t *, unsigned );
...@@ -139,7 +142,10 @@ static int DecoderOpen( vlc_object_t *p_this ) ...@@ -139,7 +142,10 @@ static int DecoderOpen( vlc_object_t *p_this )
#endif #endif
format = VLC_CODEC_FL64; format = VLC_CODEC_FL64;
decode = F64IDecode; decode = F64IDecode;
bits = 64;
break;
case VLC_CODEC_FL64: case VLC_CODEC_FL64:
decode = F64NDecode;
bits = 64; bits = 64;
break; break;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
...@@ -149,7 +155,10 @@ static int DecoderOpen( vlc_object_t *p_this ) ...@@ -149,7 +155,10 @@ static int DecoderOpen( vlc_object_t *p_this )
#endif #endif
format = VLC_CODEC_FL32; format = VLC_CODEC_FL32;
decode = F32IDecode; decode = F32IDecode;
bits = 32;
break;
case VLC_CODEC_FL32: case VLC_CODEC_FL32:
decode = F32NDecode;
bits = 32; bits = 32;
break; break;
case VLC_CODEC_U32B: case VLC_CODEC_U32B:
...@@ -506,6 +515,20 @@ static void S32IDecode( void *outp, const uint8_t *in, unsigned samples ) ...@@ -506,6 +515,20 @@ static void S32IDecode( void *outp, const uint8_t *in, unsigned samples )
} }
} }
static void F32NDecode( void *outp, const uint8_t *in, unsigned samples )
{
float *out = outp;
for( size_t i = 0; i < samples; i++ )
{
memcpy( out, in, sizeof(float) );
if( unlikely(!isfinite(*out)) )
*out = 0.f;
out++;
in += sizeof(float);
}
}
static void F32IDecode( void *outp, const uint8_t *in, unsigned samples ) static void F32IDecode( void *outp, const uint8_t *in, unsigned samples )
{ {
float *out = outp; float *out = outp;
...@@ -519,11 +542,27 @@ static void F32IDecode( void *outp, const uint8_t *in, unsigned samples ) ...@@ -519,11 +542,27 @@ static void F32IDecode( void *outp, const uint8_t *in, unsigned samples )
#else #else
s.u = GetDWBE( in ); s.u = GetDWBE( in );
#endif #endif
if( unlikely(!isfinite(s.f)) )
s.f = 0.f;
*(out++) = s.f; *(out++) = s.f;
in += 4; in += 4;
} }
} }
static void F64NDecode( void *outp, const uint8_t *in, unsigned samples )
{
double *out = outp;
for( size_t i = 0; i < samples; i++ )
{
memcpy( out, in, sizeof(double) );
if( unlikely(!isfinite( *out )) )
*out = 0.;
out++;
in += sizeof(double);
}
}
static void F64IDecode( void *outp, const uint8_t *in, unsigned samples ) static void F64IDecode( void *outp, const uint8_t *in, unsigned samples )
{ {
double *out = outp; double *out = outp;
...@@ -537,6 +576,8 @@ static void F64IDecode( void *outp, const uint8_t *in, unsigned samples ) ...@@ -537,6 +576,8 @@ static void F64IDecode( void *outp, const uint8_t *in, unsigned samples )
#else #else
s.u = GetQWBE( in ); s.u = GetQWBE( in );
#endif #endif
if( unlikely(!isfinite( s.d )) )
s.d = 0.;
*(out++) = s.d; *(out++) = s.d;
in += 8; in += 8;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment