Limit check to avoid crash in flood Fill

Reported by Shin-ichi, repaired by Pere.  Thanks!
This commit is contained in:
Bill Kendrick 2021-11-20 20:57:55 -08:00
parent e77c7766cd
commit 81fff34795

View file

@ -443,16 +443,15 @@ void simulate_flood_fill_outside_check(int x, int y, int y_outside)
/* Continue filling upwards from this scanline */ /* Continue filling upwards from this scanline */
just_queued = 0; just_queued = 0;
if (y > 0)
{
for (i = narrowFillL; i <= narrowFillR; i++) for (i = narrowFillL; i <= narrowFillR; i++)
{ {
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, i, y - 1); px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, i, y - 1);
closeness = colors_close(global_canvas, px_colr, global_old_colr); closeness = colors_close(global_canvas, px_colr, global_old_colr);
if (y > 0 && if (closeness < COLOR_MATCH_NARROW ||
(
closeness < COLOR_MATCH_NARROW ||
(closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD) (closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD)
) )
)
{ {
if (!just_queued && (global_touched == NULL || !global_touched[((y - 1) * global_canvas->w) + i])) if (!just_queued && (global_touched == NULL || !global_touched[((y - 1) * global_canvas->w) + i]))
{ {
@ -469,21 +468,21 @@ void simulate_flood_fill_outside_check(int x, int y, int y_outside)
just_queued = 0; just_queued = 0;
} }
} }
}
/* Continue filling downwards from this scanline */ /* Continue filling downwards from this scanline */
just_queued = 0; just_queued = 0;
if (y < global_canvas->h - 1)
{
for (i = narrowFillL; i <= narrowFillR; i++) for (i = narrowFillL; i <= narrowFillR; i++)
{ {
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, i, y + 1); px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, i, y + 1);
closeness = colors_close(global_canvas, px_colr, global_old_colr); closeness = colors_close(global_canvas, px_colr, global_old_colr);
if (y < global_canvas->h && if (closeness < COLOR_MATCH_NARROW ||
(
closeness < COLOR_MATCH_NARROW ||
(closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD) (closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD)
) )
)
{ {
if (!just_queued && (global_touched == NULL || !global_touched[((y + 1) * global_canvas->w) + i])) if (!just_queued && (global_touched == NULL || !global_touched[((y + 1) * global_canvas->w) + i]))
{ {
@ -500,6 +499,7 @@ void simulate_flood_fill_outside_check(int x, int y, int y_outside)
just_queued = 0; just_queued = 0;
} }
} }
}
} }