Fix stack corruption and bus errors while scanning oversized QR codes #87
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Quirc sometimes falsely detects very large QR codes (false positives). This happens for example when the camera of a smartphone is facing downwards and is recording an almost black image. When the library is trying to decode such a large QR code it accesses more memory than has previously been allocated (quirc_code→cell_bitmap). This leads to stack corruption and bus errors.
This pull requests addresses the issue by first defining a maximum supported QR code version number and defining QUIRC_MAX_BITMAP based on this maximum version number instead of using a fixed number of bytes. Later in measure_timing_pattern() QR codes exceeding the maximum allowed version number are ignored and the decoding process is aborted. This also shortens the time needed to identify and reject a bad QR code.