mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 14:44:22 +00:00
FLAC: Fix property reading of zero-length files
This commit is contained in:
parent
22664734cf
commit
77eec77897
2 changed files with 12 additions and 10 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue