mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 09:59:54 +00:00
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:
parent
40fdc3121b
commit
b1d642078f
@ -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**.
|
||||
|
||||
|
@ -109,6 +109,8 @@
|
||||
|
||||
|
||||
#define SF_MAX_CHANNELS 1024
|
||||
/* Max FLAC sample rate : https://xiph.org/flac/format.html */
|
||||
#define SF_MAX_SAMPLERATE 655350
|
||||
|
||||
|
||||
/*
|
||||
|
@ -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 ;
|
||||
|
Loading…
Reference in New Issue
Block a user