diff options
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]; } } } |