FLAC: Fix property reading of zero-length files

This commit is contained in:
Serial 2022-05-04 20:54:56 -04:00
parent 22664734cf
commit 77eec77897
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
2 changed files with 12 additions and 10 deletions

View file

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- When reading a file that doesn't provide a valid bitrate or duration, a division by zero panic would occur.
Now, it attempts to calculate the bitrate from the `mdat` atom.
- **ID3v2**: Fix reading of zero-size tags
- **FLAC**: Fix property reading of zero-length files
## [0.6.2] - 2022-04-24

View file

@ -38,17 +38,18 @@ where
// Read the remaining 32 bits of the total samples
let total_samples = stream_info.read_u32::<BigEndian>()? | (info << 28);
let (duration, overall_bitrate, audio_bitrate) = if sample_rate > 0 && total_samples > 0 {
let length = (u64::from(total_samples) * 1000) / u64::from(sample_rate);
let (mut duration, mut overall_bitrate, mut audio_bitrate) = (Duration::ZERO, None, None);
(
Duration::from_millis(length),
Some(((file_length * 8) / length) as u32),
Some(((stream_length * 8) / length) as u32),
)
} else {
(Duration::ZERO, None, None)
};
if sample_rate > 0 && total_samples > 0 {
let length = (u64::from(total_samples) * 1000) / u64::from(sample_rate);
if length > 0 {
(duration, overall_bitrate, audio_bitrate) = (
Duration::from_millis(length),
Some(((file_length * 8) / length) as u32),
Some(((stream_length * 8) / length) as u32),
);
}
}
Ok(FileProperties {
duration,