sndfile: Improve SF_INFO correctness check

Limit maximum `samplerate` and `channels` values.

Update API documentation to reflect changes.

This should also fix some possible integer overflows as:

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28441

Credit to OSS-Fuzz.
This commit is contained in:
evpobr 2021-03-18 10:28:48 +05:00
parent 40fdc3121b
commit b1d642078f
3 changed files with 9 additions and 2 deletions

View File

@ -97,6 +97,11 @@ calling **sf_open**(). The only exception to this is the case of RAW files where
the caller has to set the **samplerate**, **channels** and **format** fields to
valid values. All other fields of the structure are filled in by the library.
**Note:** The libsndfile library will reject values for **samplerate** field
that are greater than `655350` and values for field **channels** that are
greater than `1024`. These values represent the maximum theoretical limit and
may be less for specific formats.
When opening a file for write, the caller must fill in structure members
**samplerate**, **channels**, and **format**.

View File

@ -109,6 +109,8 @@
#define SF_MAX_CHANNELS 1024
/* Max FLAC sample rate : https://xiph.org/flac/format.html */
#define SF_MAX_SAMPLERATE 655350
/*

View File

@ -2881,11 +2881,11 @@ retry:
static int
validate_sfinfo (SF_INFO *sfinfo)
{ if (sfinfo->samplerate < 1)
{ if ((sfinfo->samplerate < 1) || (sfinfo->samplerate > SF_MAX_SAMPLERATE))
return 0 ;
if (sfinfo->frames < 0)
return 0 ;
if (sfinfo->channels < 1)
if ((sfinfo->channels < 1) || (sfinfo->channels > SF_MAX_CHANNELS))
return 0 ;
if ((SF_CONTAINER (sfinfo->format)) == 0)
return 0 ;