fix(tests): serve.mjs post-bind wildcard check reads the 'IPv6' family of server.address(); report-compare checks the type before opening (a FIFO or device is never opened) and again on the handle

This commit is contained in:
bchanot committed 2026-10-20 21:56:03 +02:00
1 parent d7d99b4766
commit 854d988c07
2 files changed
+18 -9

No files matched your search

+13 -8
View File
@@ -118,15 +118,20 @@ impl Files for Disk {
}
fn read(&self, path: &str) -> Result<Vec<u8>, FileFailure> {
// One open, then the checks on that handle: the path is resolved once.
// The type is checked before the open (a FIFO or a device is never opened), then
// again on the handle (the path is not swapped for a directory in between).
let regular = |meta: &fs::Metadata| {
if !meta.is_file() {
return Err(FileFailure::NotRegular);
}
if meta.len() > MAX_PDF_BYTES as u64 {
return Err(FileFailure::TooLarge);
}
Ok(())
};
regular(&fs::metadata(path).map_err(|e| failure_of(&e))?)?;
let file = fs::File::open(path).map_err(|e| failure_of(&e))?;
let meta = file.metadata().map_err(|e| failure_of(&e))?;
if !meta.is_file() {
return Err(FileFailure::NotRegular);
}
if meta.len() > MAX_PDF_BYTES as u64 {
return Err(FileFailure::TooLarge);
}
regular(&file.metadata().map_err(|e| failure_of(&e))?)?;
// Bounded read: a file that grew after the size check is still refused.
let mut bytes = Vec::new();
file.take(MAX_PDF_BYTES as u64 + 1)