Skip to content

Commit f31b069

Browse files
fix: Use UInts in envelope deserialization (#4441)
Use unsigned integers for the indexes for accessing envelope data to eliminate the risk of negative indices.
1 parent d7f68df commit f31b069

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ via the option `swizzleClassNameExclude`.
2020
- Swizzling RootUIViewController if ignored by `swizzleClassNameExclude` (#4407)
2121
- Data race in SentrySwizzleInfo.originalCalled (#4434)
2222

23+
2324
### Improvements
2425

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

2931
## 8.38.0
3032

Sources/Sentry/SentrySerialization.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ + (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data
8282
{
8383
SentryEnvelopeHeader *envelopeHeader = nil;
8484
const unsigned char *bytes = [data bytes];
85-
int envelopeHeaderIndex = 0;
85+
NSUInteger envelopeHeaderIndex = 0;
8686

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

144144
// Parse items
145-
NSInteger itemHeaderStart = envelopeHeaderIndex + 1;
145+
NSUInteger itemHeaderStart = envelopeHeaderIndex + 1;
146146

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

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

153153
NSData *itemHeaderData =

0 commit comments

Comments
 (0)