Skip to content

Commit

Permalink
mat4/mat5: fix int overflow in dataend calculation
Browse files Browse the repository at this point in the history
The clang sanitizer warns of a possible signed integer overflow when
calculating the `dataend` value in `mat4_read_header()`.

```
src/mat4.c:323:41: runtime error: signed integer overflow: 205 * -100663296 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/mat4.c:323:41 in
src/mat4.c:323:48: runtime error: signed integer overflow: 838860800 * 4 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/mat4.c:323:48 in
```

Cast the offending `rows` and `cols` ints to `sf_count_t` (the type of
`dataend` before performing the calculation, to avoid the issue.

CVE: CVE-2022-33065
Fixes: libsndfile#789
Fixes: libsndfile#833

Signed-off-by: Alex Stewart <alex.stewart@ni.com>
  • Loading branch information
amstewart committed Oct 18, 2023
1 parent 5846984 commit 57ad7b6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/mat4.c
Expand Up @@ -320,7 +320,7 @@ mat4_read_header (SF_PRIVATE *psf)
psf->filelength - psf->dataoffset, psf->sf.channels * psf->sf.frames * psf->bytewidth) ;
}
else if ((psf->filelength - psf->dataoffset) > psf->sf.channels * psf->sf.frames * psf->bytewidth)
psf->dataend = psf->dataoffset + rows * cols * psf->bytewidth ;
psf->dataend = psf->dataoffset + (sf_count_t) rows * (sf_count_t) cols * psf->bytewidth ;

psf->datalength = psf->filelength - psf->dataoffset - psf->dataend ;

Expand Down

0 comments on commit 57ad7b6

Please sign in to comment.