Closed banjun closed 7 years ago
I run into random runtime crashes on deflate(&stream, Z_FINISH) and inflate(&stream, Z_SYNC_FLUSH) when I build with Xcode 9.1.0.
deflate(&stream, Z_FINISH)
inflate(&stream, Z_SYNC_FLUSH)
Xcode: Version 9.1 (9B55) iPhone 8: iOS 11.0.3 (15A432) GzipSwift: 4.0.0 (cocoapods)
https://github.com/banjun/GzipSwiftXcode910
When Build & Run the project, randomly crash on the deflate or the inflate (or may cause malformed gunzipped data...?).
deflate
inflate
I have tried so far, Xcode 9.1 Simulator does not crash. also, building with Xcode 9.0.1 cannot cause crashes.
URLSession.dataTask response with data as OS_dispatch_data referencing numbers of 8K block data. I think this is one of the main usecases of gzip.
URLSession.dataTask
OS_dispatch_data
withUnsafeBytes codes are suspicious, especially at https://github.com/1024jp/GzipSwift/blob/72e16b884600b98ac77a871daecaea34aec87f8e/Sources/Data%2BGzip.swift#L279
withUnsafeBytes
withUnsafe... methods are not responsible for pointer uses outside the trailing closure. it actually make creating Data -> z_stream difficult. Some memory copies into a new Data with contiguous memory can resolve the crashes.
withUnsafe
Data -> z_stream
Thank you for the report and the pull-request. I've just released GzipSwift 4.0.3 with your fix.
I run into random runtime crashes on
deflate(&stream, Z_FINISH)
andinflate(&stream, Z_SYNC_FLUSH)
when I build with Xcode 9.1.0.Environment:
Xcode: Version 9.1 (9B55) iPhone 8: iOS 11.0.3 (15A432) GzipSwift: 4.0.0 (cocoapods)
minimum example project:
https://github.com/banjun/GzipSwiftXcode910
When Build & Run the project, randomly crash on the
deflate
or theinflate
(or may cause malformed gunzipped data...?).I have tried so far, Xcode 9.1 Simulator does not crash. also, building with Xcode 9.0.1 cannot cause crashes.
Reason why the example project uses fragmented data
URLSession.dataTask
response with data asOS_dispatch_data
referencing numbers of 8K block data. I think this is one of the main usecases of gzip.Analysis
withUnsafeBytes
codes are suspicious, especially at https://github.com/1024jp/GzipSwift/blob/72e16b884600b98ac77a871daecaea34aec87f8e/Sources/Data%2BGzip.swift#L279withUnsafe
... methods are not responsible for pointer uses outside the trailing closure. it actually make creatingData -> z_stream
difficult. Some memory copies into a new Data with contiguous memory can resolve the crashes.