diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2018-01-03 13:06:26 -0500 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2018-01-03 13:12:29 -0500 |
commit | 4588e6e2b98671d544f7f2bb7372710beb7bdfcb (patch) | |
tree | ddcda8503a97a19aa3975d9b5a45b7a20542c235 /objectivec | |
parent | 43caa38d6ed68129d28bf4528488e4f389a33b34 (diff) |
Force a copy when saving the NSData that came from another.
Diffstat (limited to 'objectivec')
-rw-r--r-- | objectivec/GPBMessage.m | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m index 3be20b67..cc1a650a 100644 --- a/objectivec/GPBMessage.m +++ b/objectivec/GPBMessage.m @@ -2027,7 +2027,12 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { [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]; } } } |