fix(worker): second security pass — content-only rejection codes (resource_limit, explicit list), negative proofs of the seccomp argument filters, PR_GET_DUMPABLE self-check, strict WebP chunk structure, iCCP-bomb fixture, separate test target cache; ci: release-images builder actually used (job-level DOCKER_CONFIG, --builder), literal cleanup path, token scoped to the login step, npm advisories gate, digests from build metadata
This commit is contained in:
1 parent
11813f5560
commit
a8b644a515
12 files changed
+278
-55
No files matched your search
@@ -55,8 +55,9 @@ pub fn inspect(bytes: &[u8]) -> Result<WebpSummary, WebpIssue> {
|
||||
}
|
||||
|
||||
let mut offset = 12;
|
||||
let mut chunks = Vec::new();
|
||||
let mut dimensions = None;
|
||||
let mut chunks: Vec<[u8; 4]> = Vec::new();
|
||||
let mut canvas: Option<(u32, u32)> = None;
|
||||
let mut frame: Option<(u32, u32)> = None;
|
||||
while offset < bytes.len() {
|
||||
let chunk_header = bytes
|
||||
.get(offset..offset + 8)
|
||||
@@ -79,25 +80,43 @@ pub fn inspect(bytes: &[u8]) -> Result<WebpSummary, WebpIssue> {
|
||||
if !ALLOWED_CHUNKS.contains(&&fourcc) {
|
||||
return Err(WebpIssue::ForbiddenChunk(fourcc));
|
||||
}
|
||||
let declared = match &fourcc {
|
||||
b"VP8X" => Some(parse_vp8x(payload)?),
|
||||
b"VP8 " => Some(parse_vp8(payload)?),
|
||||
b"VP8L" => Some(parse_vp8l(payload)?),
|
||||
_ => None,
|
||||
};
|
||||
// The canvas (VP8X) and the frame (VP8 / VP8L) must agree: a container whose frame
|
||||
// disagrees with its canvas is not something the encoder produces.
|
||||
match (dimensions, declared) {
|
||||
(None, Some(size)) => dimensions = Some(size),
|
||||
(Some(canvas), Some(frame)) if canvas != frame => {
|
||||
return Err(WebpIssue::BadBitstream);
|
||||
// Structure the encoder produces, and nothing else: an optional VP8X first, then an
|
||||
// optional ALPH (extended files only), then exactly one VP8 or VP8L frame.
|
||||
match &fourcc {
|
||||
b"VP8X" => {
|
||||
if !chunks.is_empty() {
|
||||
return Err(WebpIssue::BadBitstream);
|
||||
}
|
||||
canvas = Some(parse_vp8x(payload)?);
|
||||
}
|
||||
_ => {}
|
||||
b"ALPH" => {
|
||||
if canvas.is_none() || frame.is_some() {
|
||||
return Err(WebpIssue::BadBitstream);
|
||||
}
|
||||
}
|
||||
b"VP8 " | b"VP8L" => {
|
||||
if frame.is_some() {
|
||||
return Err(WebpIssue::BadBitstream);
|
||||
}
|
||||
frame = Some(if &fourcc == b"VP8 " {
|
||||
parse_vp8(payload)?
|
||||
} else {
|
||||
parse_vp8l(payload)?
|
||||
});
|
||||
}
|
||||
_ => return Err(WebpIssue::ForbiddenChunk(fourcc)),
|
||||
}
|
||||
chunks.push(fourcc);
|
||||
offset = end + (size & 1);
|
||||
}
|
||||
let (width, height) = dimensions.ok_or(WebpIssue::MissingBitstream)?;
|
||||
let frame = frame.ok_or(WebpIssue::MissingBitstream)?;
|
||||
// The canvas (VP8X) and the frame must agree: the encoder never writes otherwise.
|
||||
if let Some(canvas) = canvas
|
||||
&& canvas != frame
|
||||
{
|
||||
return Err(WebpIssue::BadBitstream);
|
||||
}
|
||||
let (width, height) = canvas.unwrap_or(frame);
|
||||
Ok(WebpSummary {
|
||||
width,
|
||||
height,
|
||||
@@ -190,15 +209,55 @@ mod tests {
|
||||
assert_eq!(inspect(&bytes), Err(WebpIssue::BadBitstream));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chunk_structure_is_strict() {
|
||||
let mut vp8 = vec![0u8; 20];
|
||||
vp8[3..6].copy_from_slice(&[0x9d, 0x01, 0x2a]);
|
||||
vp8[6..8].copy_from_slice(&512u16.to_le_bytes());
|
||||
vp8[8..10].copy_from_slice(&512u16.to_le_bytes());
|
||||
// two frames
|
||||
assert_eq!(
|
||||
inspect(&riff(&[(b"VP8 ", &vp8), (b"VP8 ", &vp8)])),
|
||||
Err(WebpIssue::BadBitstream)
|
||||
);
|
||||
// ALPH without VP8X
|
||||
assert_eq!(
|
||||
inspect(&riff(&[(b"ALPH", &[0; 4]), (b"VP8 ", &vp8)])),
|
||||
Err(WebpIssue::BadBitstream)
|
||||
);
|
||||
// VP8X not first
|
||||
assert_eq!(
|
||||
inspect(&riff(&[(b"VP8 ", &vp8), (b"VP8X", &vp8x(512, 512))])),
|
||||
Err(WebpIssue::BadBitstream)
|
||||
);
|
||||
// the encoder's extended layout
|
||||
assert!(
|
||||
expect_square(
|
||||
&riff(&[
|
||||
(b"VP8X", &vp8x(512, 512)),
|
||||
(b"ALPH", &[0; 4]),
|
||||
(b"VP8 ", &vp8)
|
||||
]),
|
||||
512
|
||||
)
|
||||
.is_ok()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn metadata_chunks_are_refused() {
|
||||
let bytes = riff(&[(b"VP8X", &vp8x(512, 512)), (b"EXIF", b"x")]);
|
||||
// refused on the chunk type before any structural rule
|
||||
assert_eq!(inspect(&bytes), Err(WebpIssue::ForbiddenChunk(*b"EXIF")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrong_sizes_are_refused() {
|
||||
let bytes = riff(&[(b"VP8X", &vp8x(511, 512))]);
|
||||
let mut vp8 = vec![0u8; 20];
|
||||
vp8[3..6].copy_from_slice(&[0x9d, 0x01, 0x2a]);
|
||||
vp8[6..8].copy_from_slice(&511u16.to_le_bytes());
|
||||
vp8[8..10].copy_from_slice(&512u16.to_le_bytes());
|
||||
let bytes = riff(&[(b"VP8X", &vp8x(511, 512)), (b"VP8 ", &vp8)]);
|
||||
assert_eq!(
|
||||
expect_square(&bytes, 512),
|
||||
Err(WebpIssue::Dimensions {
|
||||
@@ -209,6 +268,10 @@ mod tests {
|
||||
let mut truncated = riff(&[(b"VP8X", &vp8x(512, 512))]);
|
||||
truncated.pop();
|
||||
assert_eq!(inspect(&truncated), Err(WebpIssue::RiffSizeMismatch));
|
||||
assert_eq!(
|
||||
inspect(&riff(&[(b"VP8X", &vp8x(512, 512))])),
|
||||
Err(WebpIssue::MissingBitstream)
|
||||
);
|
||||
assert_eq!(inspect(b"not a webp"), Err(WebpIssue::TooShort));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user