Skip to content

Commit

Permalink
tiffcrop: fix issue #395: generation of strange section images.
Browse files Browse the repository at this point in the history
  • Loading branch information
SuLaus authored and rouault committed Mar 8, 2022
1 parent 5e18004 commit d1e3b38
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions tools/tiffcrop.c
Original file line number Diff line number Diff line change
Expand Up @@ -5841,29 +5841,39 @@ computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image,
if (orows < 1)
orows = 1;

/* If user did not specify rows and cols, set them from calcuation */
if (page->rows < 1)
page->rows = orows;
if (page->cols < 1)
page->cols = ocols;
/* Always return rows and cols from calcuation above.
* (correct values needed external to this function)
* Warn, if user input settings has been changed.
*/

if ((page->rows > 0) && (page->rows != orows)) {
TIFFError("computeOutputPixelOffsets",
"Number of user input section rows down (%"PRIu32") was changed to (%"PRIu32")", page->rows, orows);
}
page->rows = orows;
if ((page->cols > 0) && (page->cols != ocols)) {
TIFFError("computeOutputPixelOffsets",
"Number of user input section cols across (%"PRIu32") was changed to (%"PRIu32")", page->cols, ocols);
}
page->cols = ocols;

line_bytes = TIFFhowmany8(owidth * image->bps) * image->spp;
line_bytes = TIFFhowmany8(owidth * image->spp * image->bps);

if ((page->rows * page->cols) > MAX_SECTIONS)
if ((orows * ocols) > MAX_SECTIONS)
{
TIFFError("computeOutputPixelOffsets",
"Rows and Columns exceed maximum sections\nIncrease resolution or reduce sections");
return (-1);
}

/* build the list of offsets for each output section */
for (k = 0, i = 0 && k <= MAX_SECTIONS; i < orows; i++)
for (k = 0, i = 0; i < orows; i++)
{
y1 = (uint32_t)(olength * i);
y2 = (uint32_t)(olength * (i + 1) - 1);
if (y2 >= ilength)
y2 = ilength - 1;
for (j = 0; j < ocols; j++, k++)
for (j = 0; (j < ocols) && (k < MAX_SECTIONS); j++, k++)
{
x1 = (uint32_t)(owidth * j);
x2 = (uint32_t)(owidth * (j + 1) - 1);
Expand Down

0 comments on commit d1e3b38

Please sign in to comment.