1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

fix(ext/compression): throw TypeError on corrupt input (#19979)

`TypeError` should be thrown when decompressing a corrupt input
This commit is contained in:
Marcos Casagrande 2023-07-30 15:15:29 +02:00 committed by GitHub
parent 3cb260ed15
commit ee7f36afdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 24 deletions

View file

@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use deno_core::error::type_error;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::op; use deno_core::op;
use deno_core::OpState; use deno_core::OpState;
@ -74,32 +75,32 @@ pub fn op_compression_write(
let mut inner = resource.0.borrow_mut(); let mut inner = resource.0.borrow_mut();
let out: Vec<u8> = match &mut *inner { let out: Vec<u8> = match &mut *inner {
Inner::DeflateDecoder(d) => { Inner::DeflateDecoder(d) => {
d.write_all(input)?; d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?; d.flush()?;
d.get_mut().drain(..) d.get_mut().drain(..)
} }
Inner::DeflateEncoder(d) => { Inner::DeflateEncoder(d) => {
d.write_all(input)?; d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?; d.flush()?;
d.get_mut().drain(..) d.get_mut().drain(..)
} }
Inner::DeflateRawDecoder(d) => { Inner::DeflateRawDecoder(d) => {
d.write_all(input)?; d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?; d.flush()?;
d.get_mut().drain(..) d.get_mut().drain(..)
} }
Inner::DeflateRawEncoder(d) => { Inner::DeflateRawEncoder(d) => {
d.write_all(input)?; d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?; d.flush()?;
d.get_mut().drain(..) d.get_mut().drain(..)
} }
Inner::GzDecoder(d) => { Inner::GzDecoder(d) => {
d.write_all(input)?; d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?; d.flush()?;
d.get_mut().drain(..) d.get_mut().drain(..)
} }
Inner::GzEncoder(d) => { Inner::GzEncoder(d) => {
d.write_all(input)?; d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?; d.flush()?;
d.get_mut().drain(..) d.get_mut().drain(..)
} }
@ -117,12 +118,20 @@ pub fn op_compression_finish(
let resource = Rc::try_unwrap(resource).unwrap(); let resource = Rc::try_unwrap(resource).unwrap();
let inner = resource.0.into_inner(); let inner = resource.0.into_inner();
let out: Vec<u8> = match inner { let out: Vec<u8> = match inner {
Inner::DeflateDecoder(d) => d.finish()?, Inner::DeflateDecoder(d) => {
Inner::DeflateEncoder(d) => d.finish()?, d.finish().map_err(|e| type_error(e.to_string()))?
Inner::DeflateRawDecoder(d) => d.finish()?, }
Inner::DeflateRawEncoder(d) => d.finish()?, Inner::DeflateEncoder(d) => {
Inner::GzDecoder(d) => d.finish()?, d.finish().map_err(|e| type_error(e.to_string()))?
Inner::GzEncoder(d) => d.finish()?, }
Inner::DeflateRawDecoder(d) => {
d.finish().map_err(|e| type_error(e.to_string()))?
}
Inner::DeflateRawEncoder(d) => {
d.finish().map_err(|e| type_error(e.to_string()))?
}
Inner::GzDecoder(d) => d.finish().map_err(|e| type_error(e.to_string()))?,
Inner::GzEncoder(d) => d.finish().map_err(|e| type_error(e.to_string()))?,
}; };
Ok(out.into()) Ok(out.into())
} }

View file

@ -7611,18 +7611,8 @@
"decompression-constructor-error.tentative.any.worker.html": true, "decompression-constructor-error.tentative.any.worker.html": true,
"decompression-correct-input.tentative.any.html": true, "decompression-correct-input.tentative.any.html": true,
"decompression-correct-input.tentative.any.worker.html": true, "decompression-correct-input.tentative.any.worker.html": true,
"decompression-corrupt-input.tentative.any.html": [ "decompression-corrupt-input.tentative.any.html": true,
"truncating the input for 'deflate' should give an error", "decompression-corrupt-input.tentative.any.worker.html": true,
"trailing junk for 'deflate' should give an error",
"format 'deflate' field DATA should be error for 5",
"trailing junk for 'gzip' should give an error"
],
"decompression-corrupt-input.tentative.any.worker.html": [
"truncating the input for 'deflate' should give an error",
"trailing junk for 'deflate' should give an error",
"format 'deflate' field DATA should be error for 5",
"trailing junk for 'gzip' should give an error"
],
"decompression-empty-input.tentative.any.html": true, "decompression-empty-input.tentative.any.html": true,
"decompression-empty-input.tentative.any.worker.html": true, "decompression-empty-input.tentative.any.worker.html": true,
"decompression-split-chunk.tentative.any.html": true, "decompression-split-chunk.tentative.any.html": true,