Skip to content

Commit aa08344

Browse files
committed
error: Move ErrorKind::SizeMismatch to aud_io
1 parent e7a9ae2 commit aa08344

File tree

15 files changed

+50
-49
lines changed

15 files changed

+50
-49
lines changed

lofty/src/aac/read.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ use crate::error::Result;
55
use crate::id3::v2::header::Id3v2Header;
66
use crate::id3::v2::read::parse_id3v2;
77
use crate::id3::{ID3FindResults, find_id3v1};
8-
use crate::macros::{decode_err, err, parse_mode_choice};
8+
use crate::macros::{decode_err, parse_mode_choice};
99
use crate::mpeg::header::{HeaderCmpResult, cmp_header, search_for_frame_sync};
1010

1111
use std::io::{Read, Seek, SeekFrom};
1212

13+
use aud_io::err as io_err;
1314
use byteorder::ReadBytesExt;
1415

1516
#[allow(clippy::unnecessary_wraps)]
@@ -47,7 +48,7 @@ where
4748
let skip_footer = header.flags.footer;
4849

4950
let Some(new_stream_len) = stream_len.checked_sub(u64::from(header.size)) else {
50-
err!(SizeMismatch);
51+
io_err!(SizeMismatch);
5152
};
5253

5354
stream_len = new_stream_len;
@@ -72,7 +73,7 @@ where
7273
log::debug!("Skipping ID3v2 footer");
7374

7475
let Some(new_stream_len) = stream_len.checked_sub(10) else {
75-
err!(SizeMismatch);
76+
io_err!(SizeMismatch);
7677
};
7778

7879
stream_len = new_stream_len;
@@ -108,7 +109,7 @@ where
108109

109110
if header.is_some() {
110111
let Some(new_stream_len) = stream_len.checked_sub(128) else {
111-
err!(SizeMismatch);
112+
io_err!(SizeMismatch);
112113
};
113114

114115
stream_len = new_stream_len;

lofty/src/ape/read.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ use crate::id3::v1::tag::Id3v1Tag;
88
use crate::id3::v2::read::parse_id3v2;
99
use crate::id3::v2::tag::Id3v2Tag;
1010
use crate::id3::{FindId3v2Config, ID3FindResults, find_id3v1, find_id3v2, find_lyrics3v2};
11-
use crate::macros::{decode_err, err};
11+
use crate::macros::decode_err;
1212

1313
use std::io::{Read, Seek, SeekFrom};
1414

15+
use aud_io::err as io_err;
16+
1517
pub(crate) fn read_from<R>(data: &mut R, parse_options: ParseOptions) -> Result<ApeFile>
1618
where
1719
R: Read + Seek,
@@ -39,7 +41,7 @@ where
3941

4042
let Some(new_stream_length) = stream_len.checked_sub(u64::from(header.full_tag_size()))
4143
else {
42-
err!(SizeMismatch);
44+
io_err!(SizeMismatch);
4345
};
4446

4547
stream_len = new_stream_length;
@@ -88,7 +90,7 @@ where
8890
let ape_header = read_ape_header(data, false)?;
8991
let Some(new_stream_length) = stream_len.checked_sub(u64::from(ape_header.size))
9092
else {
91-
err!(SizeMismatch);
93+
io_err!(SizeMismatch);
9294
};
9395
stream_len = new_stream_length;
9496

@@ -113,7 +115,7 @@ where
113115
if id3v1_header.is_some() {
114116
id3v1_tag = id3v1;
115117
let Some(new_stream_length) = stream_len.checked_sub(128) else {
116-
err!(SizeMismatch);
118+
io_err!(SizeMismatch);
117119
};
118120

119121
stream_len = new_stream_length;
@@ -122,7 +124,7 @@ where
122124
// Next, check for a Lyrics3v2 tag, and skip over it, as it's no use to us
123125
let ID3FindResults(_, lyrics3v2_size) = find_lyrics3v2(data)?;
124126
let Some(new_stream_length) = stream_len.checked_sub(u64::from(lyrics3v2_size)) else {
125-
err!(SizeMismatch);
127+
io_err!(SizeMismatch);
126128
};
127129

128130
stream_len = new_stream_length;

lofty/src/ape/tag/read.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ use crate::ape::constants::{APE_PREAMBLE, INVALID_KEYS};
55
use crate::ape::header::{self, ApeHeader};
66
use crate::config::ParseOptions;
77
use crate::error::Result;
8-
use crate::macros::{decode_err, err, try_vec};
8+
use crate::macros::{decode_err, try_vec};
99
use crate::tag::ItemValue;
1010

1111
use std::io::{Read, Seek, SeekFrom};
1212

13+
use aud_io::err as io_err;
1314
use aud_io::text::utf8_decode;
1415
use byteorder::{LittleEndian, ReadBytesExt};
1516

@@ -31,7 +32,7 @@ where
3132

3233
let value_size = data.read_u32::<LittleEndian>()?;
3334
if value_size > remaining_size {
34-
err!(SizeMismatch);
35+
io_err!(SizeMismatch);
3536
}
3637

3738
remaining_size -= 4;

lofty/src/error.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ pub enum ErrorKind {
2424
UnknownFormat,
2525

2626
// File data related errors
27-
/// Expected the data to be a different size than provided
28-
///
29-
/// This occurs when the size of an item is written as one value, but that size is either too
30-
/// big or small to be valid within the bounds of that item.
31-
// TODO: Should probably have context
32-
SizeMismatch,
3327
/// Errors that occur while decoding a file
3428
FileDecoding(FileDecodingError),
3529
/// Errors that occur while encoding a file
@@ -50,7 +44,7 @@ pub enum ErrorKind {
5044
BadTimestamp(&'static str),
5145
/// Errors that arise while reading/writing ID3v2 tags
5246
Id3v2(Id3v2Error),
53-
47+
5448
/// Arises when attempting to use [`Atom::merge`](crate::mp4::Atom::merge) with mismatching identifiers
5549
AtomMismatch,
5650

@@ -525,10 +519,6 @@ impl Display for LoftyError {
525519
),
526520

527521
// Files
528-
ErrorKind::SizeMismatch => write!(
529-
f,
530-
"Encountered an invalid item size, either too big or too small to be valid"
531-
),
532522
ErrorKind::FileDecoding(ref file_decode_err) => write!(f, "{file_decode_err}"),
533523
ErrorKind::FileEncoding(ref file_encode_err) => write!(f, "{file_encode_err}"),
534524
}

lofty/src/flac/read.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ use crate::error::Result;
66
use crate::flac::block::{BLOCK_ID_PICTURE, BLOCK_ID_STREAMINFO, BLOCK_ID_VORBIS_COMMENTS};
77
use crate::id3::v2::read::parse_id3v2;
88
use crate::id3::{FindId3v2Config, ID3FindResults, find_id3v2};
9-
use crate::macros::{decode_err, err};
9+
use crate::macros::decode_err;
1010
use crate::ogg::read::read_comments;
1111
use crate::picture::Picture;
1212

1313
use std::io::{Read, Seek, SeekFrom};
1414

15+
use aud_io::err as io_err;
16+
1517
pub(super) fn verify_flac<R>(data: &mut R) -> Result<Block>
1618
where
1719
R: Read + Seek,
@@ -137,7 +139,7 @@ where
137139
// In the event that a block lies about its size, the current position could be
138140
// completely wrong.
139141
if current > end {
140-
err!(SizeMismatch);
142+
io_err!(SizeMismatch);
141143
}
142144

143145
(end - current, end)

lofty/src/id3/v2/write/chunk_file.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::config::WriteOptions;
22
use crate::error::{LoftyError, Result};
33
use crate::iff::chunk::Chunks;
4-
use crate::macros::err;
54

65
use std::io::{Cursor, Seek, SeekFrom, Write};
76

@@ -38,7 +37,7 @@ where
3837
file.read_to_end(file_bytes.get_mut())?;
3938

4039
if file_bytes.get_ref().len() < (actual_stream_size as usize + RIFF_CHUNK_HEADER_SIZE) {
41-
err!(SizeMismatch);
40+
io_err!(SizeMismatch);
4241
}
4342

4443
// The first chunk format is RIFF....WAVE

lofty/src/iff/chunk.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use crate::config::ParseOptions;
22
use crate::error::Result;
33
use crate::id3::v2::tag::Id3v2Tag;
4-
use crate::macros::{err, try_vec};
4+
use crate::macros::try_vec;
55

66
use std::io::{Read, Seek, SeekFrom};
77
use std::marker::PhantomData;
88

9+
use aud_io::err as io_err;
910
use aud_io::text::utf8_decode;
1011
use byteorder::{ByteOrder, ReadBytesExt};
1112

@@ -87,7 +88,7 @@ impl<B: ByteOrder> Chunks<B> {
8788
R: Read,
8889
{
8990
if size > self.remaining_size {
90-
err!(SizeMismatch);
91+
io_err!(SizeMismatch);
9192
}
9293

9394
let mut content = try_vec![0; size as usize];

lofty/src/iff/wav/read.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use crate::config::ParseOptions;
55
use crate::error::Result;
66
use crate::id3::v2::tag::Id3v2Tag;
77
use crate::iff::chunk::Chunks;
8-
use crate::macros::{decode_err, err};
8+
use crate::macros::decode_err;
99

1010
use std::io::{Read, Seek, SeekFrom};
1111

12+
use aud_io::err as io_err;
1213
use byteorder::{LittleEndian, ReadBytesExt};
1314

1415
// Verifies that the stream is a WAV file and returns the stream length
@@ -91,7 +92,7 @@ where
9192
// to avoid the seeks.
9293
let end = data.stream_position()? + u64::from(size);
9394
if end > file_len {
94-
err!(SizeMismatch);
95+
io_err!(SizeMismatch);
9596
}
9697

9798
super::tag::read::parse_riff_info(

lofty/src/iff/wav/tag/write.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::config::WriteOptions;
33
use crate::error::{LoftyError, Result};
44
use crate::iff::chunk::Chunks;
55
use crate::iff::wav::read::verify_wav;
6-
use crate::macros::err;
76

87
use std::io::{Cursor, Read, Seek, SeekFrom};
98

@@ -35,7 +34,7 @@ where
3534
file.read_to_end(file_bytes.get_mut())?;
3635

3736
if file_bytes.get_ref().len() < (stream_length as usize + RIFF_CHUNK_HEADER_SIZE) {
38-
err!(SizeMismatch);
37+
io_err!(SizeMismatch);
3938
}
4039

4140
// The first chunk format is RIFF....WAVE

lofty/src/mpeg/read.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::mpeg::header::HEADER_MASK;
1111

1212
use std::io::{Read, Seek, SeekFrom};
1313

14+
use aud_io::err as io_err;
1415
use aud_io::io::SeekStreamLen;
1516
use byteorder::{BigEndian, ReadBytesExt};
1617

@@ -164,7 +165,7 @@ where
164165
// Seek back to the start of the tag
165166
let pos = reader.stream_position()?;
166167
let Some(start_of_tag) = pos.checked_sub(u64::from(header.size)) else {
167-
err!(SizeMismatch);
168+
io_err!(SizeMismatch);
168169
};
169170

170171
reader.seek(SeekFrom::Start(start_of_tag))?;

0 commit comments

Comments
 (0)