diff --git a/src/tape/drive/mam.rs b/src/tape/drive/mam.rs index 54b8100e..a90f1655 100644 --- a/src/tape/drive/mam.rs +++ b/src/tape/drive/mam.rs @@ -115,7 +115,7 @@ fn read_tape_mam(file: &mut F) -> Result, Error> { .map(|v| v.to_vec()) } -/// Read Medium auxiliary memory attributes (cartridge memory) using raw SCSI command. +/// Read Medium auxiliary memory attributes (cartridge memory) using raw SCSI command. pub fn read_mam_attributes(file: &mut F) -> Result, Error> { let data = read_tape_mam(file)?; @@ -131,8 +131,12 @@ fn decode_mam_attributes(data: &[u8]) -> Result, Error> { let expected_len = data_len as usize; - if reader.len() != expected_len { + + if reader.len() < expected_len { bail!("read_mam_attributes: got unexpected data len ({} != {})", reader.len(), expected_len); + } else if reader.len() > expected_len { + // Note: Quantum hh7 returns the allocation_length instead of real data_len + reader = &data[4..expected_len+4]; } let mut list = Vec::new(); diff --git a/src/tape/drive/volume_statistics.rs b/src/tape/drive/volume_statistics.rs index dee7ce66..a6a11590 100644 --- a/src/tape/drive/volume_statistics.rs +++ b/src/tape/drive/volume_statistics.rs @@ -27,8 +27,8 @@ pub fn read_volume_statistics(file: &mut F) -> Result(file: &mut F) -> Result, Error> { - let buffer_size = 8192; - let mut sg_raw = SgRaw::new(file, buffer_size)?; + let alloc_len: u16 = 8192; + let mut sg_raw = SgRaw::new(file, alloc_len as usize)?; let mut cmd = Vec::new(); cmd.push(0x4D); // LOG SENSE @@ -38,7 +38,7 @@ fn sg_read_volume_statistics(file: &mut F) -> Result, Error> cmd.push(0); cmd.push(0); cmd.push(0); - cmd.push((buffer_size >> 8) as u8); cmd.push(0); // alloc len + cmd.extend(&alloc_len.to_be_bytes()); // alloc len cmd.push(0u8); // control byte sg_raw.do_command(&cmd) @@ -142,8 +142,13 @@ fn decode_volume_statistics(data: &[u8]) -> Result let page_len: u16 = unsafe { reader.read_be_value()? }; - if (page_len as usize + 4) != data.len() { + let page_len = page_len as usize; + + if (page_len + 4) > data.len() { bail!("invalid page length"); + } else { + // Note: Quantum hh7 returns the allocation_length instead of real data_len + reader = &data[4..page_len+4]; } let mut stat = Lp17VolumeStatistics::default();