Skip to content

Commit

Permalink
Force a copy when saving the NSData that came from another.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvl committed Jan 3, 2018
1 parent 43caa38 commit 4588e6e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion objectivec/GPBMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,12 @@ - (void)parseMessageSet:(GPBCodedInputStream *)input
[newInput release];
} else {
GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
[unknownFields mergeMessageSetMessage:typeId data:rawBytes];
// rawBytes was created via a NoCopy, so it can be reusing a
// subrange of another NSData that might go out of scope as things
// unwind, so a copy is needed to ensure what is saved in the
// unknown fields stays valid.
NSData *cloned = [NSData dataWithData:rawBytes];
[unknownFields mergeMessageSetMessage:typeId data:cloned];
}
}
}
Expand Down

0 comments on commit 4588e6e

Please sign in to comment.