Audit round 2 fixes: an unsafe default, four omissions, and two swallowed errors

The folder encryption probe returned "not encrypted" when it had sampled
nothing at all — a title shorter than one aligned unit skipped the loop
entirely. That verdict CLEARS the structural one an AACS directory
raised, so a genuinely encrypted folder would have been ripped as clear
and written ciphertext as video at exit 0. With no evidence it now keeps
the structural verdict, and its bounds arithmetic no longer trusts
disc-derived values not to wrap.

Reading an IFO header swallowed every I/O error and returned an empty
buffer, which sent each placement offset through unwrap_or(0) and
recorded no constraint at all — a permission error on one file produced a
silently misplaced VOB. The directory walk swallowed the same class while
claiming to skip only vanished files. Both now propagate; only NotFound
is skipped.

Four things the round-1 changes left inconsistent: two new error codes had
no doc comments, were absent from the io::Error mapping, printed no path
in Display, and were missing from the test that proves codes are distinct.
The demux sink dropped frames silently while the MKV muxer reported them.
And set_clips had been inserted INTO write_frame's doc comment, leaving
write_frame undocumented and its paragraphs describing the wrong function.

uid/gid used 0 as "not specified"; UDF's sentinel is 0xFFFFFFFF, and 0 is
root.
This commit is contained in:
Matthew Jackson
2026-08-05 17:16:03 -07:00
parent cbb3517afe
commit 60d9cc1bac
6 changed files with 88 additions and 36 deletions
+19 -6
View File
@@ -195,7 +195,11 @@ pub const E_DIR_IMAGE_FILE_CHANGED: u16 = 9065;
/// A `dir://` SOURCE folder does not fit a 32-bit sector address space
/// (> 2^32 sectors ≈ 8 TiB), or holds more entries than a UDF tree can carry.
pub const E_DIR_IMAGE_TOO_LARGE: u16 = 9066;
/// A name in the folder is too long to record in a UDF directory entry: the
/// File Identifier Descriptor stores the encoded length in one byte.
pub const E_DIR_NAME_TOO_LONG: u16 = 9067;
/// One directory in the folder holds more subdirectories than a UDF link count
/// can express (it is 16 bits, one per child plus one for its own entry).
pub const E_DIR_IMAGE_FANOUT: u16 = 9068;
pub const E_M2TS_PACKET_MALFORMED: u16 = 9021;
/// A `network://` output target resolved to no address that is safe to
@@ -1029,7 +1033,10 @@ impl std::fmt::Display for Error {
},
Error::Halted => write!(f, "E{}", self.code()),
Error::UdfNotFound { path } => write!(f, "E{}: {}", self.code(), path),
Error::DirImagePlacement { path } | Error::DirImageFileChanged { path } => {
Error::DirImagePlacement { path }
| Error::DirImageFileChanged { path }
| Error::DirNameTooLong { path }
| Error::DirImageFanout { path } => {
write!(f, "E{}: {}", self.code(), path)
}
Error::DiscTitleRange { index, count } => {
@@ -1183,15 +1190,19 @@ impl From<Error> for std::io::Error {
// 9027 insufficient space / 9029 write failed: a filesystem-level
// failure, not bad input.
E_DIR_INSUFFICIENT_SPACE | E_DIR_WRITE_FAILED => std::io::ErrorKind::Other,
// dir:// SOURCE gates (90619064, 9066): the folder handed in cannot
// be turned into a disc image — a 3D SSIF tree, an unsatisfiable
// VIDEO_TS placement, still-encrypted content, an unrecognized tree,
// or one too large to address. All are properties of the input.
// dir:// SOURCE gates (90619064, 90669068): the folder handed in
// cannot be turned into a disc image — a 3D SSIF tree, an
// unsatisfiable VIDEO_TS placement, still-encrypted content, an
// unrecognized tree, one too large to address, a name too long to
// record, or a directory whose fan-out overflows its link count.
// All are properties of the input, decided before a byte is read.
E_DIR_IMAGE_SSIF_UNSUPPORTED
| E_DIR_IMAGE_PLACEMENT
| E_DIR_IMAGE_ENCRYPTED
| E_DIR_IMAGE_UNSUPPORTED_TREE
| E_DIR_IMAGE_TOO_LARGE => std::io::ErrorKind::InvalidInput,
| E_DIR_IMAGE_TOO_LARGE
| E_DIR_NAME_TOO_LONG
| E_DIR_IMAGE_FANOUT => std::io::ErrorKind::InvalidInput,
// 9065: the folder changed underneath a running read. Not bad input
// at plan time — a mid-flight mutation of the source.
E_DIR_IMAGE_FILE_CHANGED => std::io::ErrorKind::InvalidData,
@@ -1539,6 +1550,8 @@ mod tests {
Error::DirImageUnsupportedTree.code(),
Error::DirImageFileChanged { path: "x".into() }.code(),
Error::DirImageTooLarge.code(),
Error::DirNameTooLong { path: "x".into() }.code(),
Error::DirImageFanout { path: "x".into() }.code(),
];
let mut sorted = codes.to_vec();
sorted.sort();