Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Limit decompression of UE4 crashes [INGEST-565] #1121

Merged
merged 4 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
**Bug Fixes**:

- Avoid unbounded decompression of encoded requests. A particular request crafted to inflate to large amounts of memory, such as a zip bomb, could put Relay out of memory. ([#1117](https://github.com/getsentry/relay/pull/1117))
- Avoid unbounded decompression of UE4 crash reports. Some crash reports could inflate to large amounts of memory before being checked for size, which could put Relay out of memory. ([#1121](https://github.com/getsentry/relay/pull/1121))


**Internal**:

Expand Down
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion relay-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ serde = { version = "1.0.114", features = ["derive"] }
serde_json = "1.0.55"
serde_urlencoded = "0.7.0"
smallvec = { version = "1.4.0", features = ["serde"] }
symbolic = { version = "8.0.4", optional = true, default-features=false, features=["unreal-serde"] }
symbolic = { version = "8.4.0", optional = true, default-features=false, features=["unreal-serde"] }
take_mut = "0.2.2"
tokio = { version = "1.0", features = ["rt-multi-thread"] } # in sync with reqwest
tokio-timer = "0.2.13"
Expand Down
17 changes: 11 additions & 6 deletions relay-server/src/actors/envelopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use flate2::Compression;
use futures::{future, prelude::*, sync::oneshot};
use lazy_static::lazy_static;
use serde_json::Value as SerdeValue;
use symbolic::unreal::{Unreal4Error, Unreal4ErrorKind};

use relay_auth::RelayVersion;
use relay_common::{clone, ProjectId, ProjectKey, UnixTimestamp, Uuid};
Expand Down Expand Up @@ -202,6 +203,15 @@ impl ProcessingError {
}
}

impl From<Unreal4Error> for ProcessingError {
fn from(err: Unreal4Error) -> Self {
match err.kind() {
Unreal4ErrorKind::TooLarge => Self::PayloadTooLarge,
_ => ProcessingError::InvalidUnrealReport(err),
}
}
}

/// Contains the required envelope related information to create an outcome.
#[derive(Clone, Copy, Debug)]
pub struct EnvelopeContext {
Expand Down Expand Up @@ -959,12 +969,7 @@ impl EnvelopeProcessor {
let envelope = &mut state.envelope;

if let Some(item) = envelope.take_item_by(|item| item.ty() == ItemType::UnrealReport) {
utils::expand_unreal_envelope(item, envelope)
.map_err(ProcessingError::InvalidUnrealReport)?;

if !utils::check_envelope_size_limits(&self.config, envelope) {
return Err(ProcessingError::PayloadTooLarge);
}
utils::expand_unreal_envelope(item, envelope, &self.config)?;
}

Ok(())
Expand Down
10 changes: 8 additions & 2 deletions relay-server/src/utils/unreal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use relay_config::Config;
use symbolic::unreal::{
Unreal4Context, Unreal4Crash, Unreal4Error, Unreal4FileType, Unreal4LogEntry,
Unreal4Context, Unreal4Crash, Unreal4Error, Unreal4ErrorKind, Unreal4FileType, Unreal4LogEntry,
};

use relay_general::protocol::{
Expand Down Expand Up @@ -47,9 +48,10 @@ fn get_event_item(data: &[u8]) -> Result<Option<Item>, Unreal4Error> {
pub fn expand_unreal_envelope(
unreal_item: Item,
envelope: &mut Envelope,
config: &Config,
) -> Result<(), Unreal4Error> {
let payload = unreal_item.payload();
let crash = Unreal4Crash::parse(&payload)?;
let crash = Unreal4Crash::parse_with_limit(&payload, config.max_envelope_size())?;

let mut has_event = envelope
.get_item_by(|item| item.ty() == ItemType::Event)
Expand Down Expand Up @@ -86,6 +88,10 @@ pub fn expand_unreal_envelope(
envelope.add_item(item);
}

if !super::check_envelope_size_limits(config, envelope) {
return Err(Unreal4ErrorKind::TooLarge.into());
}

Ok(())
}

Expand Down