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

[CRASH] LittleEndianByteReader.swift:33:20 #26

Closed
Lakr233 opened this issue Sep 15, 2021 · 2 comments
Closed

[CRASH] LittleEndianByteReader.swift:33:20 #26

Lakr233 opened this issue Sep 15, 2021 · 2 comments

Comments

@Lakr233
Copy link

Lakr233 commented Sep 15, 2021

I've been using your code in production for my project Saily, and found this issue in Bugsnag backend.

0  libswiftFoundation.dylib Data.subscript.getter
1  chromatic                LittleEndianByteReader.byte() (LittleEndianByteReader.swift:33:20)
2  chromatic                specialized static LZMA2.decompress(data:) (LZMA2.swift:26:54)
3  chromatic                static LZMA2.decompress(data:) (<compiler-generated>)
4  chromatic                RepositoryCenter.downloadUpdatePackage(withBaseUrl:suffix:) (RepositoryCenter+Downloader.swift:131:44)
5  chromatic                closure tsolomko/BitByteData#1 in closure #6 in RepositoryCenter.asyncUpdate(target:onComplete:) (RepositoryCenter+Internal.swift:304:39)
6  chromatic                partial apply for closure tsolomko/BitByteData#1 in closure #6 in RepositoryCenter.asyncUpdate(target:onComplete:) (<compiler-generated>)
7  chromatic                thunk for @escaping @callee_guaranteed () -> () (<compiler-generated>)
8  libdispatch.dylib        __dispatch_call_block_and_release
9 ...
libdispatch etc, etc

Currently I can not provide you the sample data about it, but will back to you if I get anything new.

Here is the full report in casue you need it.

bugsnag_error_stacktrace_EXC_BREAKPOINT_event.txt

In my project, line 33 seems to be return data[offset].

public func byte() -> UInt8 {
    defer { offset += 1 }
    return data[offset] // <--
}

And in SWCompression, (LZMA2.swift:26:54)

public static func decompress(data: Data) throws -> Data {
    let byteReader = LittleEndianByteReader(data: data)
//                                                   *
    return try decompress(byteReader, byteReader.byte()) // <--
}
@tsolomko tsolomko transferred this issue from tsolomko/BitByteData Sep 16, 2021
@tsolomko
Copy link
Owner

The line numbers seem to be off by 1 for some reason, but from what I can see from those lines, it seems you're trying to process an empty Data which causes this issue, though to confirm this I will need to look at the sample data. That said, the empty Data is not a good reason for a crash...

LittleEndianByteReader does what it was designed to do: it is the responsibility of the "user" of BitByteData to check that there is any data remaining before calling any methods. So the oversight is on SWCompression's part, and additional checks should be added there to prevent such crashes. For this reason, I transferred this issue to that repository.

The fix should be relatively straightforward, and it shouldn't take long time for me to implement it. However, since iOS 15 is coming next week, I suspect a new Swift will be released as well, so I will wait until it happens to check that nothing is broken due to that.

@tsolomko
Copy link
Owner

Fixed in 4.6.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants