mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:57:35 +00:00
LibAudio: Prevent integer overflows in intermediate FLAC calculations
Since we can have up to 32 bits of input data, multiplications may need up to 63 bits. This was accounted for in some places, but by far not in all, and oss-fuzz found multiple integer overflows. We now use i64 in all of the decoding, since we need to rescale samples to float later on anyways. If a final sample value ends up out of range (and the range can be a maximum of 32 bits), we may get samples past 1, but that then is a non-compliant input file, and using over-range samples (and most likely clipping audio) is considerably less weird than overflowing and glitching audio.
This commit is contained in:
parent
9bece0d0da
commit
59c7ce3d54
2 changed files with 31 additions and 31 deletions
|
@ -69,14 +69,14 @@ private:
|
|||
// Helper of next_frame that fetches a sub frame's header
|
||||
ErrorOr<FlacSubframeHeader, LoaderError> next_subframe_header(BigEndianInputBitStream& bit_input, u8 channel_index);
|
||||
// Helper of next_frame that decompresses a subframe
|
||||
ErrorOr<Vector<i32>, LoaderError> parse_subframe(FlacSubframeHeader& subframe_header, BigEndianInputBitStream& bit_input);
|
||||
ErrorOr<Vector<i64>, LoaderError> parse_subframe(FlacSubframeHeader& subframe_header, BigEndianInputBitStream& bit_input);
|
||||
// Subframe-internal data decoders (heavy lifting)
|
||||
ErrorOr<Vector<i32>, LoaderError> decode_fixed_lpc(FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input);
|
||||
ErrorOr<Vector<i32>, LoaderError> decode_verbatim(FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input);
|
||||
ErrorOr<Vector<i32>, LoaderError> decode_custom_lpc(FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input);
|
||||
MaybeLoaderError decode_residual(Vector<i32>& decoded, FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input);
|
||||
ErrorOr<Vector<i64>, LoaderError> decode_fixed_lpc(FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input);
|
||||
ErrorOr<Vector<i64>, LoaderError> decode_verbatim(FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input);
|
||||
ErrorOr<Vector<i64>, LoaderError> decode_custom_lpc(FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input);
|
||||
MaybeLoaderError decode_residual(Vector<i64>& decoded, FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input);
|
||||
// decode a single rice partition that has its own rice parameter
|
||||
ALWAYS_INLINE ErrorOr<Vector<i32>, LoaderError> decode_rice_partition(u8 partition_type, u32 partitions, u32 partition_index, FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input);
|
||||
ALWAYS_INLINE ErrorOr<Vector<i64>, LoaderError> decode_rice_partition(u8 partition_type, u32 partitions, u32 partition_index, FlacSubframeHeader& subframe, BigEndianInputBitStream& bit_input);
|
||||
MaybeLoaderError load_seektable(FlacRawMetadataBlock&);
|
||||
// Note that failing to read a Vorbis comment block is not treated as an error of the FLAC loader, since metadata is optional.
|
||||
void load_vorbis_comment(FlacRawMetadataBlock&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue