diff --git a/crates/core/src/bin/report_compare.rs b/crates/core/src/bin/report_compare.rs index 35503a16..3d8756bb 100644 --- a/crates/core/src/bin/report_compare.rs +++ b/crates/core/src/bin/report_compare.rs @@ -118,15 +118,20 @@ impl Files for Disk { } fn read(&self, path: &str) -> Result, 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) diff --git a/scripts/browser/serve.mjs b/scripts/browser/serve.mjs index c6bf5158..93b12655 100644 --- a/scripts/browser/serve.mjs +++ b/scripts/browser/serve.mjs @@ -36,8 +36,12 @@ const WILDCARDS = new BlockList() WILDCARDS.addAddress('0.0.0.0', 'ipv4') WILDCARDS.addAddress('::', 'ipv6') +// `dns.lookup` reports the family as 6, `server.address()` as 'IPv6'. const isWildcard = ({ address, family }) => - WILDCARDS.check(address.replace(/%.*$/, ''), family === 6 ? 'ipv6' : 'ipv4') + WILDCARDS.check( + address.replace(/%.*$/, ''), + family === 6 || family === 'IPv6' ? 'ipv6' : 'ipv4', + ) /** * The one address `host` names, resolved before any socket exists: an empty