ref: 58ecb1ac15cadec832fc5e539c250b0a6b1a0b90
parent: 280c060bb11919aad4b96a60a2542a49ee3d5a0b
author: Gregory Maxwell <[email protected]>
date: Mon May 9 09:16:30 EDT 2011
The encoder would crash in the PVQ search if fed NaNs via the float interface. This patch protects against it in two sufficient ways: Making the PVQ search robust against NaNs and by squashing NaNs to zero on input. Thanks to David Richards for reporting this failure mode.
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -1086,6 +1086,8 @@
x = SCALEIN(*pcmp);
#ifndef FIXED_POINT
+ if (!(x==x))
+ x = 0;
if (st->clip)
x = MAX32(-65536.f, MIN32(65536.f,x));
#endif
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -223,7 +223,9 @@
#ifdef FIXED_POINT
if (sum <= K)
#else
- if (sum <= EPSILON)
+ /* Prevents infinities and NaNs from causing too many pulses
+ to be allocated. 64 is an approximation of infinity here. */
+ if (!(sum > EPSILON && sum < 64))
#endif
{
X[0] = QCONST16(1.f,14);