_ZN10FuzzHelperC2EPKhm:
   22|    348|{
   23|    348|}
_ZN10FuzzHelper8doChecksEv:
   27|    348|{
   28|    348|    Pl_Discard discard;
   29|    348|    Pl_LZWDecoder p("decode", &discard, false);
   30|    348|    p.write(const_cast<unsigned char*>(data), size);
   31|    348|    p.finish();
   32|    348|}
_ZN10FuzzHelper3runEv:
   36|    348|{
   37|    348|    try {
   38|    348|        doChecks();
   39|    348|    } catch (std::runtime_error const& e) {
   40|     52|        std::cerr << "runtime_error: " << e.what() << std::endl;
   41|     52|    }
   42|    348|}
LLVMFuzzerTestOneInput:
   46|    348|{
   47|    348|    FuzzHelper f(data, size);
   48|    348|    f.run();
   49|    348|    return 0;
   50|    348|}

_ZN8PipelineD2Ev:
   53|    696|    virtual ~Pipeline() = default;

_ZN5QIntC7to_uintImEEjRKT_:
  207|   750k|    {
  208|   750k|        return IntConverter<T, unsigned int>::convert(i);
  209|   750k|    }
_ZN5QIntC12IntConverterImjLb0ELb0EE7convertERKm:
   68|   750k|        {
   69|       |            // From and To are both unsigned.
   70|   750k|            if (i > std::numeric_limits<To>::max()) {
  ------------------
  |  Branch (70:17): [True: 0, False: 750k]
  ------------------
   71|      0|                error(i);
   72|      0|            }
   73|   750k|            return static_cast<To>(i);
   74|   750k|        }

_ZN3QTC2TCEPKcS1_i:
   35|  2.65k|    {
   36|       |#ifndef QPDF_DISABLE_QTC
   37|       |        TC_real(scope, ccase, n);
   38|       |#endif // QPDF_DISABLE_QTC
   39|  2.65k|    }

_ZN6Buffer7MembersC2EmPhb:
   22|   742k|{
   23|   742k|    if (own_memory) {
  ------------------
  |  Branch (23:9): [True: 742k, False: 0]
  ------------------
   24|   742k|        this->buf = (size ? new unsigned char[size] : nullptr);
  ------------------
  |  Branch (24:22): [True: 742k, False: 0]
  ------------------
   25|   742k|    } else {
   26|      0|        this->buf = buf;
   27|      0|    }
   28|   742k|}
_ZN6Buffer7MembersD2Ev:
   39|   742k|{
   40|   742k|    if (this->own_memory) {
  ------------------
  |  Branch (40:9): [True: 742k, False: 0]
  ------------------
   41|   742k|        delete[] this->buf;
   42|   742k|    }
   43|   742k|}
_ZN6BufferC2Em:
   52|   742k|{
   53|   742k|}
_ZN6BufferC2EOS_:
   86|   949k|{
   87|   949k|}
_ZNK6Buffer7getSizeEv:
  109|  16.6k|{
  110|  16.6k|    return m->size;
  111|  16.6k|}
_ZN6Buffer9getBufferEv:
  121|   766k|{
  122|   766k|    return m->buf;
  123|   766k|}

_ZN8PipelineC2EPKcPS_:
    9|    696|{
   10|    696|}
_ZN8Pipeline7getNextEb:
   14|   744k|{
   15|   744k|    if ((this->next == nullptr) && (!allow_null)) {
  ------------------
  |  Branch (15:9): [True: 0, False: 744k]
  |  Branch (15:36): [True: 0, False: 0]
  ------------------
   16|      0|        throw std::logic_error(
   17|      0|            this->identifier + ": Pipeline::getNext() called on pipeline with no next");
   18|      0|    }
   19|   744k|    return this->next;
   20|   744k|}

_ZN10Pl_DiscardC2Ev:
    7|    348|{
    8|    348|}
_ZN10Pl_DiscardD2Ev:
   11|    348|{
   12|       |    // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer
   13|    348|}
_ZN10Pl_Discard5writeEPKhm:
   17|   744k|{
   18|   744k|}
_ZN10Pl_Discard6finishEv:
   22|    296|{
   23|    296|}

_ZN13Pl_LZWDecoderC2EPKcP8Pipelineb:
   19|    348|{
   20|    348|    memset(buf, 0, 3);
   21|    348|}
_ZN13Pl_LZWDecoder5writeEPKhm:
   25|    348|{
   26|   951k|    for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (26:24): [True: 950k, False: 348]
  ------------------
   27|   950k|        this->buf[next++] = bytes[i];
   28|   950k|        if (this->next == 3) {
  ------------------
  |  Branch (28:13): [True: 316k, False: 634k]
  ------------------
   29|   316k|            this->next = 0;
   30|   316k|        }
   31|   950k|        this->bits_available += 8;
   32|   950k|        if (this->bits_available >= this->code_size) {
  ------------------
  |  Branch (32:13): [True: 747k, False: 203k]
  ------------------
   33|   747k|            sendNextCode();
   34|   747k|        }
   35|   950k|    }
   36|    348|}
_ZN13Pl_LZWDecoder6finishEv:
   40|    296|{
   41|    296|    getNext()->finish();
   42|    296|}
_ZN13Pl_LZWDecoder12sendNextCodeEv:
   46|   747k|{
   47|   747k|    unsigned int high = this->byte_pos;
   48|   747k|    unsigned int med = (this->byte_pos + 1) % 3;
   49|   747k|    unsigned int low = (this->byte_pos + 2) % 3;
   50|       |
   51|   747k|    unsigned int bits_from_high = 8 - this->bit_pos;
   52|   747k|    unsigned int bits_from_med = this->code_size - bits_from_high;
   53|   747k|    unsigned int bits_from_low = 0;
   54|   747k|    if (bits_from_med > 8) {
  ------------------
  |  Branch (54:9): [True: 144k, False: 602k]
  ------------------
   55|   144k|        bits_from_low = bits_from_med - 8;
   56|   144k|        bits_from_med = 8;
   57|   144k|    }
   58|   747k|    unsigned int high_mask = (1U << bits_from_high) - 1U;
   59|   747k|    unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U);
   60|   747k|    unsigned int low_mask = 0xff - ((1U << (8 - bits_from_low)) - 1U);
   61|   747k|    unsigned int code = 0;
   62|   747k|    code += (this->buf[high] & high_mask) << bits_from_med;
   63|   747k|    code += ((this->buf[med] & med_mask) >> (8 - bits_from_med));
   64|   747k|    if (bits_from_low) {
  ------------------
  |  Branch (64:9): [True: 144k, False: 602k]
  ------------------
   65|   144k|        code <<= bits_from_low;
   66|   144k|        code += ((this->buf[low] & low_mask) >> (8 - bits_from_low));
   67|   144k|        this->byte_pos = low;
   68|   144k|        this->bit_pos = bits_from_low;
   69|   602k|    } else {
   70|   602k|        this->byte_pos = med;
   71|   602k|        this->bit_pos = bits_from_med;
   72|   602k|    }
   73|   747k|    if (this->bit_pos == 8) {
  ------------------
  |  Branch (73:9): [True: 59.1k, False: 688k]
  ------------------
   74|  59.1k|        this->bit_pos = 0;
   75|  59.1k|        ++this->byte_pos;
   76|  59.1k|        this->byte_pos %= 3;
   77|  59.1k|    }
   78|   747k|    this->bits_available -= this->code_size;
   79|       |
   80|   747k|    handleCode(code);
   81|   747k|}
_ZN13Pl_LZWDecoder12getFirstCharEj:
   85|  8.40k|{
   86|  8.40k|    unsigned char result = '\0';
   87|  8.40k|    if (code < 256) {
  ------------------
  |  Branch (87:9): [True: 547, False: 7.85k]
  ------------------
   88|    547|        result = static_cast<unsigned char>(code);
   89|  7.85k|    } else if (code > 257) {
  ------------------
  |  Branch (89:16): [True: 7.85k, False: 0]
  ------------------
   90|  7.85k|        unsigned int idx = code - 258;
   91|  7.85k|        if (idx >= table.size()) {
  ------------------
  |  Branch (91:13): [True: 0, False: 7.85k]
  ------------------
   92|      0|            throw std::runtime_error("Pl_LZWDecoder::getFirstChar: table overflow");
   93|      0|        }
   94|  7.85k|        Buffer& b = table.at(idx);
   95|  7.85k|        result = b.getBuffer()[0];
   96|  7.85k|    } else {
   97|      0|        throw std::runtime_error(
   98|      0|            "Pl_LZWDecoder::getFirstChar called with invalid code (" + std::to_string(code) + ")");
   99|      0|    }
  100|  8.40k|    return result;
  101|  8.40k|}
_ZN13Pl_LZWDecoder10addToTableEh:
  105|   742k|{
  106|   742k|    unsigned int last_size = 0;
  107|   742k|    unsigned char const* last_data = nullptr;
  108|   742k|    unsigned char tmp[1];
  109|       |
  110|   742k|    if (this->last_code < 256) {
  ------------------
  |  Branch (110:9): [True: 734k, False: 8.24k]
  ------------------
  111|   734k|        tmp[0] = static_cast<unsigned char>(this->last_code);
  112|   734k|        last_data = tmp;
  113|   734k|        last_size = 1;
  114|   734k|    } else if (this->last_code > 257) {
  ------------------
  |  Branch (114:16): [True: 8.24k, False: 0]
  ------------------
  115|  8.24k|        unsigned int idx = this->last_code - 258;
  116|  8.24k|        if (idx >= table.size()) {
  ------------------
  |  Branch (116:13): [True: 0, False: 8.24k]
  ------------------
  117|      0|            throw std::runtime_error("Pl_LZWDecoder::addToTable: table overflow");
  118|      0|        }
  119|  8.24k|        Buffer& b = table.at(idx);
  120|  8.24k|        last_data = b.getBuffer();
  121|  8.24k|        last_size = QIntC::to_uint(b.getSize());
  122|  8.24k|    } else {
  123|      0|        throw std::runtime_error(
  124|      0|            "Pl_LZWDecoder::addToTable called with invalid code (" +
  125|      0|            std::to_string(this->last_code) + ")");
  126|      0|    }
  127|       |
  128|   742k|    Buffer entry(1 + last_size);
  129|   742k|    unsigned char* new_data = entry.getBuffer();
  130|   742k|    memcpy(new_data, last_data, last_size);
  131|   742k|    new_data[last_size] = next;
  132|   742k|    this->table.push_back(std::move(entry));
  133|   742k|}
_ZN13Pl_LZWDecoder10handleCodeEj:
  137|   747k|{
  138|   747k|    if (this->eod) {
  ------------------
  |  Branch (138:9): [True: 752, False: 746k]
  ------------------
  139|    752|        return;
  140|    752|    }
  141|       |
  142|   746k|    if (code == 256) {
  ------------------
  |  Branch (142:9): [True: 2.08k, False: 744k]
  ------------------
  143|  2.08k|        if (!this->table.empty()) {
  ------------------
  |  Branch (143:13): [True: 1.34k, False: 738]
  ------------------
  144|  1.34k|            QTC::TC("libtests", "Pl_LZWDecoder intermediate reset");
  145|  1.34k|        }
  146|  2.08k|        this->table.clear();
  147|  2.08k|        this->code_size = 9;
  148|   744k|    } else if (code == 257) {
  ------------------
  |  Branch (148:16): [True: 17, False: 744k]
  ------------------
  149|     17|        this->eod = true;
  150|   744k|    } else {
  151|   744k|        if (this->last_code != 256) {
  ------------------
  |  Branch (151:13): [True: 742k, False: 1.83k]
  ------------------
  152|       |            // Add to the table from last time.  New table entry would be what we read last plus the
  153|       |            // first character of what we're reading now.
  154|   742k|            unsigned char next = '\0';
  155|   742k|            unsigned int table_size = QIntC::to_uint(table.size());
  156|   742k|            if (code < 256) {
  ------------------
  |  Branch (156:17): [True: 734k, False: 8.44k]
  ------------------
  157|       |                // just read < 256; last time's next was code
  158|   734k|                next = static_cast<unsigned char>(code);
  159|   734k|            } else if (code > 257) {
  ------------------
  |  Branch (159:24): [True: 8.44k, False: 0]
  ------------------
  160|  8.44k|                size_t idx = code - 258;
  161|  8.44k|                if (idx > table_size) {
  ------------------
  |  Branch (161:21): [True: 39, False: 8.40k]
  ------------------
  162|     39|                    throw std::runtime_error("LZWDecoder: bad code received");
  163|  8.40k|                } else if (idx == table_size) {
  ------------------
  |  Branch (163:28): [True: 1.30k, False: 7.09k]
  ------------------
  164|       |                    // The encoder would have just created this entry, so the first character of
  165|       |                    // this entry would have been the same as the first character of the last entry.
  166|  1.30k|                    QTC::TC("libtests", "Pl_LZWDecoder last was table size");
  167|  1.30k|                    next = getFirstChar(this->last_code);
  168|  7.09k|                } else {
  169|  7.09k|                    next = getFirstChar(code);
  170|  7.09k|                }
  171|  8.44k|            }
  172|   742k|            unsigned int new_idx = 258 + table_size;
  173|   742k|            if (new_idx == 4096) {
  ------------------
  |  Branch (173:17): [True: 4, False: 742k]
  ------------------
  174|      4|                throw std::runtime_error("LZWDecoder: table full");
  175|      4|            }
  176|   742k|            addToTable(next);
  177|   742k|            unsigned int change_idx = new_idx + code_change_delta;
  178|   742k|            if ((change_idx == 511) || (change_idx == 1023) || (change_idx == 2047)) {
  ------------------
  |  Branch (178:17): [True: 754, False: 741k]
  |  Branch (178:40): [True: 449, False: 741k]
  |  Branch (178:64): [True: 228, False: 741k]
  ------------------
  179|  1.43k|                ++this->code_size;
  180|  1.43k|            }
  181|   742k|        }
  182|       |
  183|   744k|        if (code < 256) {
  ------------------
  |  Branch (183:13): [True: 735k, False: 8.41k]
  ------------------
  184|   735k|            auto ch = static_cast<unsigned char>(code);
  185|   735k|            getNext()->write(&ch, 1);
  186|   735k|        } else {
  187|  8.41k|            unsigned int idx = code - 258;
  188|  8.41k|            if (idx >= table.size()) {
  ------------------
  |  Branch (188:17): [True: 9, False: 8.40k]
  ------------------
  189|      9|                throw std::runtime_error("Pl_LZWDecoder::handleCode: table overflow");
  190|      9|            }
  191|  8.40k|            Buffer& b = table.at(idx);
  192|  8.40k|            getNext()->write(b.getBuffer(), b.getSize());
  193|  8.40k|        }
  194|   744k|    }
  195|       |
  196|   746k|    this->last_code = code;
  197|   746k|}

_ZN13Pl_LZWDecoderD2Ev:
   13|    348|    ~Pl_LZWDecoder() override = default;

