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

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

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

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

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

_ZN8PipelineC2EPKcPS_:
    9|    660|{
   10|    660|}
_ZN8Pipeline7getNextEb:
   14|   865k|{
   15|   865k|    if ((this->next == nullptr) && (!allow_null)) {
  ------------------
  |  Branch (15:9): [True: 0, False: 865k]
  |  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|   865k|    return this->next;
   20|   865k|}

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

_ZN13Pl_LZWDecoderC2EPKcP8Pipelineb:
   19|    330|{
   20|    330|    memset(buf, 0, 3);
   21|    330|}
_ZN13Pl_LZWDecoder5writeEPKhm:
   25|    330|{
   26|  1.10M|    for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (26:24): [True: 1.10M, False: 330]
  ------------------
   27|  1.10M|        this->buf[next++] = bytes[i];
   28|  1.10M|        if (this->next == 3) {
  ------------------
  |  Branch (28:13): [True: 368k, False: 736k]
  ------------------
   29|   368k|            this->next = 0;
   30|   368k|        }
   31|  1.10M|        this->bits_available += 8;
   32|  1.10M|        if (this->bits_available >= this->code_size) {
  ------------------
  |  Branch (32:13): [True: 869k, False: 235k]
  ------------------
   33|   869k|            sendNextCode();
   34|   869k|        }
   35|  1.10M|    }
   36|    330|}
_ZN13Pl_LZWDecoder6finishEv:
   40|    281|{
   41|    281|    getNext()->finish();
   42|    281|}
_ZN13Pl_LZWDecoder12sendNextCodeEv:
   46|   869k|{
   47|   869k|    unsigned int high = this->byte_pos;
   48|   869k|    unsigned int med = (this->byte_pos + 1) % 3;
   49|   869k|    unsigned int low = (this->byte_pos + 2) % 3;
   50|       |
   51|   869k|    unsigned int bits_from_high = 8 - this->bit_pos;
   52|   869k|    unsigned int bits_from_med = this->code_size - bits_from_high;
   53|   869k|    unsigned int bits_from_low = 0;
   54|   869k|    if (bits_from_med > 8) {
  ------------------
  |  Branch (54:9): [True: 144k, False: 724k]
  ------------------
   55|   144k|        bits_from_low = bits_from_med - 8;
   56|   144k|        bits_from_med = 8;
   57|   144k|    }
   58|   869k|    unsigned int high_mask = (1U << bits_from_high) - 1U;
   59|   869k|    unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U);
   60|   869k|    unsigned int low_mask = 0xff - ((1U << (8 - bits_from_low)) - 1U);
   61|   869k|    unsigned int code = 0;
   62|   869k|    code += (this->buf[high] & high_mask) << bits_from_med;
   63|   869k|    code += ((this->buf[med] & med_mask) >> (8 - bits_from_med));
   64|   869k|    if (bits_from_low) {
  ------------------
  |  Branch (64:9): [True: 144k, False: 724k]
  ------------------
   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|   724k|    } else {
   70|   724k|        this->byte_pos = med;
   71|   724k|        this->bit_pos = bits_from_med;
   72|   724k|    }
   73|   869k|    if (this->bit_pos == 8) {
  ------------------
  |  Branch (73:9): [True: 90.0k, False: 779k]
  ------------------
   74|  90.0k|        this->bit_pos = 0;
   75|  90.0k|        ++this->byte_pos;
   76|  90.0k|        this->byte_pos %= 3;
   77|  90.0k|    }
   78|   869k|    this->bits_available -= this->code_size;
   79|       |
   80|   869k|    handleCode(code);
   81|   869k|}
_ZN13Pl_LZWDecoder12getFirstCharEj:
   85|  12.5k|{
   86|  12.5k|    unsigned char result = '\0';
   87|  12.5k|    if (code < 256) {
  ------------------
  |  Branch (87:9): [True: 375, False: 12.1k]
  ------------------
   88|    375|        result = static_cast<unsigned char>(code);
   89|  12.1k|    } else if (code > 257) {
  ------------------
  |  Branch (89:16): [True: 12.1k, False: 0]
  ------------------
   90|  12.1k|        unsigned int idx = code - 258;
   91|  12.1k|        if (idx >= table.size()) {
  ------------------
  |  Branch (91:13): [True: 0, False: 12.1k]
  ------------------
   92|      0|            throw std::runtime_error("Pl_LZWDecoder::getFirstChar: table overflow");
   93|      0|        }
   94|  12.1k|        Buffer& b = table.at(idx);
   95|  12.1k|        result = b.getBuffer()[0];
   96|  12.1k|    } else {
   97|      0|        throw std::runtime_error(
   98|      0|            "Pl_LZWDecoder::getFirstChar called with invalid code (" + std::to_string(code) + ")");
   99|      0|    }
  100|  12.5k|    return result;
  101|  12.5k|}
_ZN13Pl_LZWDecoder10addToTableEh:
  105|   863k|{
  106|   863k|    unsigned int last_size = 0;
  107|   863k|    unsigned char const* last_data = nullptr;
  108|   863k|    unsigned char tmp[1];
  109|       |
  110|   863k|    if (this->last_code < 256) {
  ------------------
  |  Branch (110:9): [True: 851k, False: 12.3k]
  ------------------
  111|   851k|        tmp[0] = static_cast<unsigned char>(this->last_code);
  112|   851k|        last_data = tmp;
  113|   851k|        last_size = 1;
  114|   851k|    } else if (this->last_code > 257) {
  ------------------
  |  Branch (114:16): [True: 12.3k, False: 0]
  ------------------
  115|  12.3k|        unsigned int idx = this->last_code - 258;
  116|  12.3k|        if (idx >= table.size()) {
  ------------------
  |  Branch (116:13): [True: 0, False: 12.3k]
  ------------------
  117|      0|            throw std::runtime_error("Pl_LZWDecoder::addToTable: table overflow");
  118|      0|        }
  119|  12.3k|        Buffer& b = table.at(idx);
  120|  12.3k|        last_data = b.getBuffer();
  121|  12.3k|        last_size = QIntC::to_uint(b.getSize());
  122|  12.3k|    } 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|   863k|    Buffer entry(1 + last_size);
  129|   863k|    unsigned char* new_data = entry.getBuffer();
  130|   863k|    memcpy(new_data, last_data, last_size);
  131|   863k|    new_data[last_size] = next;
  132|   863k|    this->table.push_back(std::move(entry));
  133|   863k|}
_ZN13Pl_LZWDecoder10handleCodeEj:
  137|   869k|{
  138|   869k|    if (this->eod) {
  ------------------
  |  Branch (138:9): [True: 1.76k, False: 867k]
  ------------------
  139|  1.76k|        return;
  140|  1.76k|    }
  141|       |
  142|   867k|    if (code == 256) {
  ------------------
  |  Branch (142:9): [True: 1.89k, False: 865k]
  ------------------
  143|  1.89k|        if (!this->table.empty()) {
  ------------------
  |  Branch (143:13): [True: 1.08k, False: 815]
  ------------------
  144|  1.08k|            QTC::TC("libtests", "Pl_LZWDecoder intermediate reset");
  145|  1.08k|        }
  146|  1.89k|        this->table.clear();
  147|  1.89k|        this->code_size = 9;
  148|   865k|    } else if (code == 257) {
  ------------------
  |  Branch (148:16): [True: 21, False: 865k]
  ------------------
  149|     21|        this->eod = true;
  150|   865k|    } else {
  151|   865k|        if (this->last_code != 256) {
  ------------------
  |  Branch (151:13): [True: 863k, False: 1.74k]
  ------------------
  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|   863k|            unsigned char next = '\0';
  155|   863k|            unsigned int table_size = QIntC::to_uint(table.size());
  156|   863k|            if (code < 256) {
  ------------------
  |  Branch (156:17): [True: 851k, False: 12.6k]
  ------------------
  157|       |                // just read < 256; last time's next was code
  158|   851k|                next = static_cast<unsigned char>(code);
  159|   851k|            } else if (code > 257) {
  ------------------
  |  Branch (159:24): [True: 12.6k, False: 0]
  ------------------
  160|  12.6k|                size_t idx = code - 258;
  161|  12.6k|                if (idx > table_size) {
  ------------------
  |  Branch (161:21): [True: 40, False: 12.5k]
  ------------------
  162|     40|                    throw std::runtime_error("LZWDecoder: bad code received");
  163|  12.5k|                } else if (idx == table_size) {
  ------------------
  |  Branch (163:28): [True: 920, False: 11.6k]
  ------------------
  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|    920|                    QTC::TC("libtests", "Pl_LZWDecoder last was table size");
  167|    920|                    next = getFirstChar(this->last_code);
  168|  11.6k|                } else {
  169|  11.6k|                    next = getFirstChar(code);
  170|  11.6k|                }
  171|  12.6k|            }
  172|   863k|            unsigned int new_idx = 258 + table_size;
  173|   863k|            if (new_idx == 4096) {
  ------------------
  |  Branch (173:17): [True: 1, False: 863k]
  ------------------
  174|      1|                throw std::runtime_error("LZWDecoder: table full");
  175|      1|            }
  176|   863k|            addToTable(next);
  177|   863k|            unsigned int change_idx = new_idx + code_change_delta;
  178|   863k|            if ((change_idx == 511) || (change_idx == 1023) || (change_idx == 2047)) {
  ------------------
  |  Branch (178:17): [True: 810, False: 863k]
  |  Branch (178:40): [True: 562, False: 862k]
  |  Branch (178:64): [True: 311, False: 862k]
  ------------------
  179|  1.68k|                ++this->code_size;
  180|  1.68k|            }
  181|   863k|        }
  182|       |
  183|   865k|        if (code < 256) {
  ------------------
  |  Branch (183:13): [True: 853k, False: 12.5k]
  ------------------
  184|   853k|            auto ch = static_cast<unsigned char>(code);
  185|   853k|            getNext()->write(&ch, 1);
  186|   853k|        } else {
  187|  12.5k|            unsigned int idx = code - 258;
  188|  12.5k|            if (idx >= table.size()) {
  ------------------
  |  Branch (188:17): [True: 8, False: 12.5k]
  ------------------
  189|      8|                throw std::runtime_error("Pl_LZWDecoder::handleCode: table overflow");
  190|      8|            }
  191|  12.5k|            Buffer& b = table.at(idx);
  192|  12.5k|            getNext()->write(b.getBuffer(), b.getSize());
  193|  12.5k|        }
  194|   865k|    }
  195|       |
  196|   867k|    this->last_code = code;
  197|   867k|}

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

