diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2021-12-26 09:16:41 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2021-12-26 09:16:41 +0000 |
commit | e15e137ba527ba97c82149ad8c6bed59088d8616 (patch) | |
tree | d97d0742d8fa448232faad05a7b40ccc18641b68 /converter/pbm/mgrtopbm.c | |
parent | 2d31b9e0a06dde404131dbc2300502bfd2698819 (diff) | |
download | netpbm-mirror-e15e137ba527ba97c82149ad8c6bed59088d8616.tar.gz netpbm-mirror-e15e137ba527ba97c82149ad8c6bed59088d8616.tar.xz netpbm-mirror-e15e137ba527ba97c82149ad8c6bed59088d8616.zip |
Release 10.73.38
git-svn-id: http://svn.code.sf.net/p/netpbm/code/super_stable@4219 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/pbm/mgrtopbm.c')
-rw-r--r-- | converter/pbm/mgrtopbm.c | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/converter/pbm/mgrtopbm.c b/converter/pbm/mgrtopbm.c index 9f7004a1..712e3be9 100644 --- a/converter/pbm/mgrtopbm.c +++ b/converter/pbm/mgrtopbm.c @@ -16,6 +16,48 @@ static void +interpHdrWidth(struct b_header const head, + unsigned int * const colsP) { + + if (head.h_wide < ' ' || head.l_wide < ' ') + pm_error("Invalid width field in MGR header"); + else { + unsigned int const maxDimension = 4095; + + unsigned int const cols = + (((int)head.h_wide - ' ') << 6) + ((int)head.l_wide - ' '); + + if (cols == 0 || cols > maxDimension) + pm_error("Invalid width value (%u) in MGR header", cols); + else + *colsP = cols; + } +} + + + +static void +interpHdrHeight(struct b_header const head, + unsigned int * const rowsP) { + + if (head.h_high < ' ' || head.l_high < ' ') + pm_error("Invalid height field in MGR header"); + else { + unsigned int const maxDimension = 4095; + + unsigned int const rows = + (((int)head.h_high - ' ') << 6) + ((int)head.l_high - ' '); + + if (rows == 0 || rows > maxDimension) + pm_error("Invalid height value (%u) in MGR header", rows); + else + *rowsP = rows; + } +} + + + +static void readMgrHeader(FILE * const ifP, unsigned int * const colsP, unsigned int * const rowsP, @@ -60,13 +102,9 @@ readMgrHeader(FILE * const ifP, pad = 0; /* should never reach here */ } - if (head.h_wide < ' ' || head.l_wide < ' ') - pm_error("Invalid width field in MGR header"); - if (head.h_high < ' ' || head.l_high < ' ') - pm_error("Invalid width field in MGR header"); + interpHdrWidth (head, colsP); + interpHdrHeight(head, rowsP); - *colsP = (((int)head.h_wide - ' ') << 6) + ((int)head.l_wide - ' '); - *rowsP = (((int)head.h_high - ' ') << 6) + ((int) head.l_high - ' '); *padrightP = ( ( *colsP + pad - 1 ) / pad ) * pad - *colsP; } |