avoid out of range array access in JBIG2 decoder

This commit is contained in:
fkaelberer 2015-01-23 09:13:50 +01:00
parent 801902c6cc
commit 8013100ab8

View File

@ -179,10 +179,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
// At each pixel: Clear contextLabel pixels that are shifted // At each pixel: Clear contextLabel pixels that are shifted
// out of the context, then add new ones. // out of the context, then add new ones.
// If j + n is out of range at the right image border, then
// the undefined value of bitmap[i - 2][j + n] is shifted to 0
contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) | contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
(row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel; (j + 3 < width ? row2[j + 3] << 11 : 0) |
(j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
} }
} }