Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 additions & 1 deletion lib/identify.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,15 @@ static void find_alignment_pattern(struct quirc *q, int index)
/* Spiral outwards from the estimate point until we find something
* roughly the right size. Don't look too far from the estimate
* point.
*
* A degenerate perspective transform (near-zero denominator) can make
* size_estimate enormous, spinning this spiral for hundreds of millions
* of iterations on a tiny image (denial of service on a crafted QR). The
* alignment pattern must lie within the image, so also cap the search
* radius at the image size.
*/
while (step_size * step_size < size_estimate * 100) {
int max_step = (q->w > q->h ? q->w : q->h) + 1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

Suggested change
int max_step = (q->w > q->h ? q->w : q->h) + 1;
const int max_step = (q->w > q->h ? q->w : q->h) + 1;

while (step_size * step_size < size_estimate * 100 && step_size <= max_step) {
static const int dx_map[] = {1, 0, -1, 0};
static const int dy_map[] = {0, -1, 0, 1};
int i;
Expand Down
3 changes: 2 additions & 1 deletion lib/quirc.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ int quirc_resize(struct quirc *q, int w, int h)
* old buffer when the new size is greater and (b) to write beyond the
* new buffer when the new size is smaller, hence the min computation.
*/
(void)memcpy(image, q->image, min);
if (min)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking

Suggested change
if (min)
if (min > 0)

(void)memcpy(image, q->image, min);

/* alloc a new buffer for q->pixels if needed */
if (!QUIRC_PIXEL_ALIAS_IMAGE) {
Expand Down