-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CVE-2022-36114: limit the maximum unpacked size of a crate to 512MB
This gives users of custom registries the same protections, using the same size limit that crates.io uses. `LimitErrorReader` code copied from crates.io.
- Loading branch information
1 parent
dafe4a7
commit d1f9553
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use std::io::{self, Read, Take}; | ||
|
||
#[derive(Debug)] | ||
pub struct LimitErrorReader<R> { | ||
inner: Take<R>, | ||
} | ||
|
||
impl<R: Read> LimitErrorReader<R> { | ||
pub fn new(r: R, limit: u64) -> LimitErrorReader<R> { | ||
LimitErrorReader { | ||
inner: r.take(limit), | ||
} | ||
} | ||
} | ||
|
||
impl<R: Read> Read for LimitErrorReader<R> { | ||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||
match self.inner.read(buf) { | ||
Ok(0) if self.inner.limit() == 0 => Err(io::Error::new( | ||
io::ErrorKind::Other, | ||
"maximum limit reached when reading", | ||
)), | ||
e => e, | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters