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

issue with image.c #2805

Closed
michaelrsweet opened this issue Apr 17, 2008 · 3 comments
Closed

issue with image.c #2805

michaelrsweet opened this issue Apr 17, 2008 · 3 comments

Comments

@michaelrsweet
Copy link
Collaborator

Version: 1.3.7
CUPS.org User: kssingvo.suse

Ludwig Nussel asked me to report this issue:

What happened with the following problem? AFAICS the sample image
causes a crash due to a NULL deref. However, the calloc returning
that NULL just does that due to a silly value that is the result of
a multiplication (image.c, get_tile()):

xtiles = (img->xsize + CUPS_TILE_SIZE - 1) / CUPS_TILE_SIZE;
ytiles = (img->ysize + CUPS_TILE_SIZE - 1) / CUPS_TILE_SIZE;
...
tile = calloc(sizeof(cups_itile_t), xtiles * ytiles);
...
for (tilex = xtiles; tilex > 0; tilex --, tile ++)
tile->pos = -1;

Couldn't xtiles and xtiles theoretically be constructed in a way
that xtiles*ytiles < xtiles so that the loop overwrites memory?

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Fixed in Subversion repository.

Please verify the attached patch - basically I've rearranged the multiplications so that calloc() will be able to check for overflow.

xtiles and ytiles will always be less than 2^24, and the _cups_itile_t structure is 12 bytes on 32-bit archs (where this overflow is an issue).

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

This STR has not been updated by the submitter for two or more weeks and has been closed as required by the CUPS Configuration Management Plan. If the issue still requires resolution, please re-submit a new STR.

@michaelrsweet
Copy link
Collaborator Author

"str2805.patch":

Index: image.c

--- image.c (revision 7471)
+++ image.c (working copy)
@@ -725,7 +725,7 @@
if ((img->tiles = calloc(sizeof(cups_itile_t *), ytiles)) == NULL)
return (NULL);

  • if ((tile = calloc(sizeof(cups_itile_t), xtiles * ytiles)) == NULL)
  • if ((tile = calloc(xtiles * sizeof(cups_itile_t), ytiles)) == NULL)
    return (NULL);

for (tiley = 0; tiley < ytiles; tiley ++)

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

No branches or pull requests

1 participant