convertbmp: fix issues with zero bitmasks 1148/head
authorHugo Lefeuvre <hle@debian.org>
Sat, 22 Sep 2018 18:33:19 +0000 (14:33 -0400)
committerHugo Lefeuvre <hle@debian.org>
Sat, 22 Sep 2018 18:51:50 +0000 (14:51 -0400)
commitca16fe55014c57090dd97369256c7657aeb25975
treefa3b135a1d01fa031105f728342794943ef00bf7
parent9d1a9dc20dd5155bab977a4f53d05c4bbd66533a
convertbmp: fix issues with zero bitmasks

In the case where a BMP file declares compression 3 (BI_BITFIELDS)
with header size <= 56, all bitmask values keep their initialization
value 0. This may lead to various undefined behavior later e.g. when
doing 1 << (l_comp->prec - 1).

This issue does not affect files with bit count 16 because of a check
added in 16240e2 which sets default values to the color masks if they
are all 0.

This commit adds similar checks for the 32 bit case.

Also, if a BMP file declares compression 3 with header size >= 56 and
intentional 0 bitmasks, the same issue will be triggered in both the
16 and 32 bit count case.

This commit adds checks to bmp_read_info_header() rejecting BMP files
with "intentional" 0 bitmasks. These checks might be removed in the
future when proper handling of zero bitmasks will be available in
openjpeg2.

fixes #1057 (CVE-2018-5785)
src/bin/jp2/convertbmp.c