Skip to content

Commit

Permalink
fix: Use UInts in envelope deserialization (#4441)
Browse files Browse the repository at this point in the history
Use unsigned integers for the indexes for accessing envelope data to
eliminate the risk of negative indices.
  • Loading branch information
philipphofmann authored Oct 15, 2024
1 parent d7f68df commit f31b069
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ via the option `swizzleClassNameExclude`.
- Swizzling RootUIViewController if ignored by `swizzleClassNameExclude` (#4407)
- Data race in SentrySwizzleInfo.originalCalled (#4434)


### Improvements

- Serializing profile on a BG Thread (#4377) to avoid potentially slightly blocking the main thread.
- Session Replay performance for SwiftUI (#4419)
- Speed up getBinaryImages (#4435) for finishing transactions and capturing events
- Use UInts in envelope deserialization (#4441)

## 8.38.0

Expand Down
8 changes: 4 additions & 4 deletions Sources/Sentry/SentrySerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ + (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data
{
SentryEnvelopeHeader *envelopeHeader = nil;
const unsigned char *bytes = [data bytes];
int envelopeHeaderIndex = 0;
NSUInteger envelopeHeaderIndex = 0;

for (int i = 0; i < data.length; ++i) {
for (NSUInteger i = 0; i < data.length; ++i) {
if (bytes[i] == '\n') {
envelopeHeaderIndex = i;
// Envelope header end
Expand Down Expand Up @@ -142,12 +142,12 @@ + (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data
}

// Parse items
NSInteger itemHeaderStart = envelopeHeaderIndex + 1;
NSUInteger itemHeaderStart = envelopeHeaderIndex + 1;

NSMutableArray<SentryEnvelopeItem *> *items = [NSMutableArray new];
NSUInteger endOfEnvelope = data.length - 1;

for (NSInteger i = itemHeaderStart; i <= endOfEnvelope; ++i) {
for (NSUInteger i = itemHeaderStart; i <= endOfEnvelope; ++i) {
if (bytes[i] == '\n' || i == endOfEnvelope) {

NSData *itemHeaderData =
Expand Down

0 comments on commit f31b069

Please sign in to comment.