NSJSONSerialization crashes on iOS 13

Originator:johnnie.tseng
Number:rdar://7458717 Date Originated:2019/11/21
Status:Open Resolved:NO
Product:iOS Product Version:13
Classification:Bug Reproducible:YES
 
【FB7458717】

- [Demo project]
https://github.com/JohnnyTseng/NSJSONSerialization-Crash-Demo

- [Description]
NSJSONSerialization crashes on iOS 13 when a string cannot be transformed to UTF-8 string

- [Steps to reproduce]
Download the demo project, run on iOS 13 devices (with Zombie object enabled), and it crashes.

- [Expected result]
To generate an error, and not crash the application
"Error Domain=NSCocoaErrorDomain Code=3852 "The string 0xXXXXXXX failed to convert to UTF8" UserInfo={NSDebugDescription=The string 0xXXXXXXX failed to convert to UTF8}"

- [Actual Result]
Crashes on iOS 13 devices with a "-[NSError retain]: message sent to deallocated instance" message

Comments

Fixed in 14

This is fixed in 14.0 (18A373) - the code produces output as expected: (well, not sure about first line, but the Error looks right).

NSJSONSerializationDemo(11762,0x102cf7880) malloc: enabling scribbling to detect mods to free blocks 2020-10-07 12:28:11.218779+0100 NSJSONSerializationDemo[11762:6968803] Data: (null), Error: Error Domain=NSCocoaErrorDomain Code=3852 "The string 0x103808800 failed to convert to UTF8" UserInfo={NSDebugDescription=The string 0x103808800 failed to convert to UTF8}


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!