From 222718b7e7b5e1f6082363c66f55bcf0738caa2e Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Thu, 3 Sep 2009 18:50:08 -0400 Subject: [PATCH] Correctly set the value of symCodeLen From 6.5.8.2.3, symCodeLen = ceil(log2(numInputSyms + numNewSyms)). The old code was taking 1+floor, which provides the wrong answer when they sum to a power of two. Signed-off-by: David Benjamin --- poppler/JBIG2Stream.cc | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/poppler/JBIG2Stream.cc b/poppler/JBIG2Stream.cc index fec0e2d..97994bd 100644 --- a/poppler/JBIG2Stream.cc +++ b/poppler/JBIG2Stream.cc @@ -1587,12 +1587,15 @@ GBool JBIG2Stream::readSymbolDictSeg(Guint segNum, Guint length, goto eofError; } - // compute symbol code length + // compute symbol code length, per 6.5.8.2.3 + // symCodeLen = ceil( log2( numInputSyms + numNewSyms ) ) symCodeLen = 1; - i = (numInputSyms + numNewSyms) >> 1; - while (i) { - ++symCodeLen; - i >>= 1; + if (likely(numInputSyms + numNewSyms > 0)) { // don't fail too badly if the sum is 0 + i = (numInputSyms + numNewSyms - 1) >> 1; + while (i) { + ++symCodeLen; + i >>= 1; + } } // get the input symbol bitmaps -- 1.6.0.4