diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2021-12-27 17:33:56 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2021-12-27 17:33:56 +0000 |
commit | 6e629f983aa205c3eaa5f339f1c71bb5e7938049 (patch) | |
tree | a89f594443ac2330138f0bd0f19ee59135c2213f /lib/libpam.c | |
parent | ec52f41aabc9de9aac203c2f462252e403c7374a (diff) | |
download | netpbm-mirror-6e629f983aa205c3eaa5f339f1c71bb5e7938049.tar.gz netpbm-mirror-6e629f983aa205c3eaa5f339f1c71bb5e7938049.tar.xz netpbm-mirror-6e629f983aa205c3eaa5f339f1c71bb5e7938049.zip |
Promote Development to Advanced to make Release 10.97.00
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@4222 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libpam.c')
-rw-r--r-- | lib/libpam.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/libpam.c b/lib/libpam.c index 72502749..b24f230e 100644 --- a/lib/libpam.c +++ b/lib/libpam.c @@ -90,7 +90,12 @@ validateComputableSize(struct pam * const pamP) { the size of a tuple row, in bytes, can be represented by an 'int'. Another common operation is adding 1 or 2 to the highest row, column, - or plane number in the image, so we make sure that's possible. + or plane number in the image, so we make sure that's possible. And in + bitmap images, rounding up to multiple of 8 is common, so we provide for + that too. + + Note that it's still the programmer's responsibility to ensure that his + code, using values known to have been validated here, cannot overflow. -----------------------------------------------------------------------------*/ if (pamP->width == 0) pm_error("Width is zero. Image must be at least one pixel wide"); @@ -111,10 +116,10 @@ validateComputableSize(struct pam * const pamP) { if (depth > INT_MAX - 2) pm_error("image depth (%u) too large to be processed", depth); - if (pamP->width > INT_MAX - 2) + if (pamP->width > INT_MAX - 10) pm_error("image width (%u) too large to be processed", pamP->width); - if (pamP->height > INT_MAX - 2) + if (pamP->height > INT_MAX - 10) pm_error("image height (%u) too large to be processed", pamP->height); } @@ -416,6 +421,20 @@ pnm_setpamrow(const struct pam * const pamP, +static void +setSeekableAndRasterPos(struct pam * const pamP) { + + if (pamP->size >= PAM_STRUCT_SIZE(is_seekable)) + pamP->is_seekable = pm_is_seekable(pamP->file); + + if (pamP->size >= PAM_STRUCT_SIZE(raster_pos)) { + if (pamP->is_seekable) + pm_tell2(pamP->file, &pamP->raster_pos, sizeof(pamP->raster_pos)); + } +} + + + #define MAX_LABEL_LENGTH 8 #define MAX_VALUE_LENGTH 255 @@ -945,6 +964,8 @@ pnm_readpaminit(FILE * const file, pamP->plainformat = FALSE; /* See below for complex explanation of why this is FALSE. */ + setSeekableAndRasterPos(pamP); + interpretTupleType(pamP); validateComputableSize(pamP); @@ -1053,8 +1074,6 @@ pnm_writepaminit(struct pam * const pamP) { interpretTupleType(pamP); - pamP->len = MIN(pamP->size, PAM_STRUCT_SIZE(opacity_plane)); - switch (PAM_FORMAT_TYPE(pamP->format)) { case PAM_TYPE: /* See explanation below of why we ignore 'pm_plain_output' here. */ @@ -1113,6 +1132,10 @@ pnm_writepaminit(struct pam * const pamP) { pm_error("Invalid format passed to pnm_writepaminit(): %d", pamP->format); } + + setSeekableAndRasterPos(pamP); + + pamP->len = MIN(pamP->size, PAM_STRUCT_SIZE(raster_pos)); } |