1024jp / GzipSwift

Swift package that enables gzip/gunzip Data using zlib
MIT License
544 stars 134 forks source link

GzipSwift + JSONSerialization causes an EXC_BAD_ACCESS error in Xcode 10.2 #35

Closed samanthamjohn closed 5 years ago

samanthamjohn commented 5 years ago

Using Xcode 10.2 Swift 4.2

I made a small test project to demonstrate the issue (copying in the Gzip extension from master) here.

it seems that the second iteration of this loop in the gzipped function causes the crash:

    while stream.avail_out == 0 {
            if Int(stream.total_out) >= data.count {
                data.count += DataSize.chunk
            }

            data.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<Bytef>) in
                stream.next_out = bytes.advanced(by: Int(stream.total_out))
            }
            stream.avail_out = uInt(data.count) - uInt(stream.total_out)

            deflate(&stream, Z_FINISH)
        }

I'm not super familiar with the stream APIs so I'm not exactly sure what's going on. Thank you!

samanthamjohn commented 5 years ago

Ah, I see this is the same issue as https://github.com/1024jp/GzipSwift/issues/34. The title is misleading because it only refers to Swift 5 compatibility, whereas the library seems to just be broken in Xcode 10.2 Also, it's a bug, not an enhancement!