private void decodeSymbolInstances()

in src/main/java/org/apache/pdfbox/jbig2/segments/TextRegion.java [435:507]


    private void decodeSymbolInstances()
            throws IOException, InvalidHeaderValueException, IntegerMaxValueException
    {

        long stripT = decodeStripT();

        /* Last two sentences of 6.4.5 2) */
        long firstS = 0;
        long instanceCounter = 0;

        /* 6.4.5 3 a) */
        while (instanceCounter < amountOfSymbolInstances)
        {

            final long dT = decodeDT();
            stripT += dT;
            long dfS = 0;

            /* 3 c) symbol instances in the strip */
            boolean first = true;
            currentS = 0;

            // do until OOB
            for (;;)
            {
                /* 3 c) i) - first symbol instance in the strip */
                if (first)
                {
                    /* 6.4.7 */
                    dfS = decodeDfS();
                    firstS += dfS;
                    currentS = firstS;
                    first = false;
                    /* 3 c) ii) - the remaining symbol instances in the strip */
                }
                else
                {
                    /* 6.4.8 */
                    final long idS = decodeIdS();

                    /*
                     * If result is OOB, then all the symbol instances in this strip have been decoded; proceed to step
                     * 3 d) respectively 3 b). Also exit, if the expected number of instances have been decoded.
                     * 
                     * The latter exit condition guards against pathological cases where a strip's S never contains OOB
                     * and thus never terminates as illustrated in
                     * https://bugs.chromium.org/p/chromium/issues/detail?id=450971 case pdfium-loop2.pdf.
                     */
                    if (idS == Long.MAX_VALUE || instanceCounter >= amountOfSymbolInstances)
                        break;

                    currentS += (idS + sbdsOffset);
                }

                /* 3 c) iii) */
                final long currentT = decodeCurrentT();
                final long t = stripT + currentT;

                /* 3 c) iv) */
                final long id = decodeID();

                /* 3 c) v) */
                final long r = decodeRI();
                /* 6.4.11 */
                final Bitmap ib = decodeIb(r, id);

                /* vi) */
                blit(ib, t);

                instanceCounter++;
            }
        }
    }