Skip to content

EXC_BAD_ACCESS at QOI decode. #2

@serge-ivamov

Description

@serge-ivamov

Hi.

When trying to decode the TestImage.png from the demo application directory, I get an EXC_BAD_ACCESS error.
The problem appears to be an incorrect calculation of the data size (dataCount). The qoi_decode function returns a pointer to a buffer containing only raw pixel data, not the entire QOI file structure, including the header or padding.

Fix:

--- a/Sources/Swift-QOI/QOICoder.swift
+++ b/Sources/Swift-QOI/QOICoder.swift
@@ -50,8 +50,7 @@ final public class QOICoder {
         let height = Int(desc.height)
         let width = Int(desc.width)
 
-        let pixelCount = height * width
-        let dataCount = pixelCount * (Int(channels) + 1) + Mirror(reflecting: SQOI.qoi_padding).children.count + Int(SQOI.QOI_HEADER_SIZE)
+        let dataCount = height * width * Int(channels) // fix for EXC_BAD_ACCESS
 
         let qoiData = Data(bytes: pixelData, count: dataCount)
         return qoiData

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions