Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GT-2478 Fix Fuzi crash in Xcode 16.2 #2387

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions godtools/App/Share/Data/WebArchiveQueue/HTMLDocumentWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@ import Fuzi
import libxml2

// NOTE: Wrapper for addressing bad access starting in Xcode 16.2 Fuzi version 3.1.3. (https://github.com/cezheng/Fuzi/issues/130)
// Will fix by implementing change from open PR (https://github.com/cezheng/Fuzi/pull/131).
// TODO: GT-2492 Once merged we can remove this wrapper. ~Levi

class HTMLDocumentWrapper {

let htmlDocument: HTMLDocument

init(string: String, encoding: String.Encoding = String.Encoding.utf8) throws {

guard let cChars = string.cString(using: encoding) else {
throw XMLError.invalidData
}

let buffer = cChars.withUnsafeBufferPointer { buffer in
UnsafeBufferPointer(rebasing: buffer[0..<buffer.count])
let mutablebuffer = UnsafeMutableBufferPointer<CChar>.allocate(capacity: cChars.count)
_ = mutablebuffer.initialize(from: cChars)

defer {
mutablebuffer.deallocate()
}

// NOTE: Seems to solve bad access at line 130 in Document.swift Fuzi version 3.1.3. "guard let document = type(of: self).parse(buffer: buffer, options: options)" ~Levi

let buffer = UnsafeBufferPointer(mutablebuffer)

let htmlDocument = try HTMLDocument(buffer: buffer)

self.htmlDocument = htmlDocument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,12 @@ class WebArchiveOperation: Operation, @unchecked Sendable {
do {
let webArchiveResource: WebArchiveResource = WebArchiveResource(url: url, data: data, mimeType: mimeType)
let mainResource: WebArchiveMainResource = WebArchiveMainResource(baseResource: webArchiveResource)
//let htmlDocument: HTMLDocument = try HTMLDocument(string: htmlString, encoding: .utf8) // NOTE: Was getting a bad access starting in Xcode 16.2 (https://github.com/cezheng/Fuzi/issues/130). ~Levi
let htmlDocumentWrapper = try HTMLDocumentWrapper(string: htmlString, encoding: .utf8)
let resourceUrls: [String] = htmlDocumentWrapper.htmlDocument.getHTMLReferences(host: host, includeJavascript: includeJavascript)

// NOTE: Using HTMLDocumentWrapper for now with open PR fix until merged and Fuzi is updated. ~Levi
// TODO: GT-2492 Remove HTMLDocumentWrapper once PR is merged. ~Levi
//let htmlDocument: HTMLDocument = try HTMLDocument(string: htmlString, encoding: .utf8)
let htmlDocument: HTMLDocument = try HTMLDocumentWrapper(string: htmlString, encoding: .utf8).htmlDocument
let resourceUrls: [String] = htmlDocument.getHTMLReferences(host: host, includeJavascript: includeJavascript)
complete(.success(HTMLDocumentData(mainResource: mainResource, resourceUrls: resourceUrls)))
}
catch let parseHtmlDocumentError {
Expand Down
Loading