summaryrefslogtreecommitdiff
path: root/ext/web/compression.rs
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2023-07-30 15:15:29 +0200
committerGitHub <noreply@github.com>2023-07-30 09:15:29 -0400
commitee7f36afdb60084203a31455f327672fbff6d9aa (patch)
tree7d3a2b2f28b7b89c0bfbd0373aeb1ce2141e1ecf /ext/web/compression.rs
parent3cb260ed15a26785272bb09427504a565010963d (diff)
fix(ext/compression): throw TypeError on corrupt input (#19979)
`TypeError` should be thrown when decompressing a corrupt input
Diffstat (limited to 'ext/web/compression.rs')
-rw-r--r--ext/web/compression.rs33
1 files changed, 21 insertions, 12 deletions
diff --git a/ext/web/compression.rs b/ext/web/compression.rs
index 557bff6ba..1ebb453b8 100644
--- a/ext/web/compression.rs
+++ b/ext/web/compression.rs
@@ -1,5 +1,6 @@
// 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::op;
use deno_core::OpState;
@@ -74,32 +75,32 @@ pub fn op_compression_write(
let mut inner = resource.0.borrow_mut();
let out: Vec<u8> = match &mut *inner {
Inner::DeflateDecoder(d) => {
- d.write_all(input)?;
+ d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?;
d.get_mut().drain(..)
}
Inner::DeflateEncoder(d) => {
- d.write_all(input)?;
+ d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?;
d.get_mut().drain(..)
}
Inner::DeflateRawDecoder(d) => {
- d.write_all(input)?;
+ d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?;
d.get_mut().drain(..)
}
Inner::DeflateRawEncoder(d) => {
- d.write_all(input)?;
+ d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?;
d.get_mut().drain(..)
}
Inner::GzDecoder(d) => {
- d.write_all(input)?;
+ d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?;
d.get_mut().drain(..)
}
Inner::GzEncoder(d) => {
- d.write_all(input)?;
+ d.write_all(input).map_err(|e| type_error(e.to_string()))?;
d.flush()?;
d.get_mut().drain(..)
}
@@ -117,12 +118,20 @@ pub fn op_compression_finish(
let resource = Rc::try_unwrap(resource).unwrap();
let inner = resource.0.into_inner();
let out: Vec<u8> = match inner {
- Inner::DeflateDecoder(d) => d.finish()?,
- Inner::DeflateEncoder(d) => d.finish()?,
- Inner::DeflateRawDecoder(d) => d.finish()?,
- Inner::DeflateRawEncoder(d) => d.finish()?,
- Inner::GzDecoder(d) => d.finish()?,
- Inner::GzEncoder(d) => d.finish()?,
+ Inner::DeflateDecoder(d) => {
+ d.finish().map_err(|e| type_error(e.to_string()))?
+ }
+ Inner::DeflateEncoder(d) => {
+ d.finish().map_err(|e| type_error(e.to_string()))?
+ }
+ 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())
}