Audit fixes + DVD support foundation (IFO, PS demux, MPEG-2, CSS crack)
Audit fixes (14 critical, 22 warnings): - UDF: bounds checks on all ICB/FID parsing from disc data - SCSI Linux: saturating_sub on residual, CDB length guard, buffer size guard - SCSI macOS: SCSITaskStatus u32 (was u8 — stack corruption) - AACS: EC mod_inv returns infinity instead of panic, key reduced mod n - AACS: do_handshake tries all host certs (was returning on first failure) - H.264: bounds check on SPS < 4 bytes - ContentReader: error on missing unit key (was zero-fill) - KEYDB: flat redirect loop (was recursive), 100MB response limit, Windows HOME fallback - ISO writer: AVDP extent order, partition length, allocation cap - Network: removed TCP_NODELAY on bulk stream - MKV: guard on u64::MAX seek - disc.rs: saturating_sub on extent offset, simplified dead region code - cargo fmt (610 violations), cargo clippy --fix (55 auto-fixes) DVD support (new files): - src/ifo.rs — IFO parser (VIDEO_TS.IFO, VTS_XX_0.IFO, PGC chains, cells, streams) — 13 tests - src/mux/ps.rs — MPEG-2 Program Stream demuxer (pack headers, PES, private stream 1) — 12 tests - src/mux/codec/mpeg2.rs — MPEG-2 video parser (sequence headers, I-frame detection) — 15 tests - src/css/crack.rs — split-attack algorithm (LFSR cipher needs verification — test ignored) 226 tests total (was 186), 1 ignored (CSS crack needs cipher verification).
This commit is contained in:
+47
-24
@@ -3,14 +3,15 @@
|
||||
//! Read-only stream. Wraps DriveSession + Disc.
|
||||
//! Handles drive init, AACS decryption, and sector reading.
|
||||
|
||||
use std::io::{self, Read, Write};
|
||||
use std::path::Path;
|
||||
use super::IOStream;
|
||||
use crate::disc::{DiscTitle, Disc};
|
||||
use crate::disc::{Disc, DiscTitle};
|
||||
use crate::drive::DriveSession;
|
||||
use crate::error::Error;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::path::Path;
|
||||
|
||||
/// Options for opening a disc stream.
|
||||
#[derive(Default)]
|
||||
pub struct DiscOptions {
|
||||
/// Device path (e.g. "/dev/sg4"). None = auto-detect.
|
||||
pub device: Option<String>,
|
||||
@@ -20,11 +21,6 @@ pub struct DiscOptions {
|
||||
pub title_index: Option<usize>,
|
||||
}
|
||||
|
||||
impl Default for DiscOptions {
|
||||
fn default() -> Self {
|
||||
Self { device: None, keydb_path: None, title_index: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// Optical disc stream. Read-only — yields decrypted BD-TS bytes.
|
||||
pub struct DiscStream {
|
||||
@@ -44,8 +40,9 @@ impl DiscStream {
|
||||
pub fn open(opts: DiscOptions) -> Result<Self, Error> {
|
||||
let device = match opts.device {
|
||||
Some(ref d) => crate::drive::resolve_device(d)?.0,
|
||||
None => crate::drive::find_drive()
|
||||
.ok_or_else(|| Error::DeviceNotFound { path: String::new() })?,
|
||||
None => crate::drive::find_drive().ok_or_else(|| Error::DeviceNotFound {
|
||||
path: String::new(),
|
||||
})?,
|
||||
};
|
||||
|
||||
let mut session = DriveSession::open(Path::new(&device))?;
|
||||
@@ -61,24 +58,38 @@ impl DiscStream {
|
||||
|
||||
let title_index = opts.title_index.unwrap_or(0);
|
||||
if title_index >= disc.titles.len() {
|
||||
return Err(Error::DiscTitleRange { index: title_index, count: disc.titles.len() });
|
||||
return Err(Error::DiscTitleRange {
|
||||
index: title_index,
|
||||
count: disc.titles.len(),
|
||||
});
|
||||
}
|
||||
let disc_title = disc.titles[title_index].clone();
|
||||
|
||||
Ok(Self {
|
||||
disc_title, disc, session, title_index,
|
||||
batch_buf: Vec::new(), batch_pos: 0,
|
||||
started: false, eof: false,
|
||||
disc_title,
|
||||
disc,
|
||||
session,
|
||||
title_index,
|
||||
batch_buf: Vec::new(),
|
||||
batch_pos: 0,
|
||||
started: false,
|
||||
eof: false,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the full Disc (for listing all titles, etc.)
|
||||
pub fn disc(&self) -> &Disc { &self.disc }
|
||||
pub fn disc(&self) -> &Disc {
|
||||
&self.disc
|
||||
}
|
||||
}
|
||||
|
||||
impl IOStream for DiscStream {
|
||||
fn info(&self) -> &DiscTitle { &self.disc_title }
|
||||
fn finish(&mut self) -> io::Result<()> { Ok(()) }
|
||||
fn info(&self) -> &DiscTitle {
|
||||
&self.disc_title
|
||||
}
|
||||
fn finish(&mut self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for DiscStream {
|
||||
@@ -91,7 +102,9 @@ impl Read for DiscStream {
|
||||
return Ok(n);
|
||||
}
|
||||
|
||||
if self.eof { return Ok(0); }
|
||||
if self.eof {
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
// Open reader on first call
|
||||
if !self.started {
|
||||
@@ -100,8 +113,10 @@ impl Read for DiscStream {
|
||||
|
||||
// Read next batch via a temporary ContentReader
|
||||
// ContentReader borrows session and disc, so we create it inline
|
||||
let mut reader = self.disc.open_title(&mut self.session, self.title_index)
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?;
|
||||
let mut reader = self
|
||||
.disc
|
||||
.open_title(&mut self.session, self.title_index)
|
||||
.map_err(|e| io::Error::other(e.to_string()))?;
|
||||
|
||||
match reader.read_batch() {
|
||||
Ok(Some(batch)) => {
|
||||
@@ -116,15 +131,23 @@ impl Read for DiscStream {
|
||||
}
|
||||
Ok(n)
|
||||
}
|
||||
Ok(None) => { self.eof = true; Ok(0) }
|
||||
Err(e) => Err(io::Error::new(io::ErrorKind::Other, e.to_string())),
|
||||
Ok(None) => {
|
||||
self.eof = true;
|
||||
Ok(0)
|
||||
}
|
||||
Err(e) => Err(io::Error::other(e.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for DiscStream {
|
||||
fn write(&mut self, _buf: &[u8]) -> io::Result<usize> {
|
||||
Err(io::Error::new(io::ErrorKind::Unsupported, "disc is read-only"))
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Unsupported,
|
||||
"disc is read-only",
|
||||
))
|
||||
}
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user