LLVMFuzzerTestOneInput:
   36|    372|{
   37|    372|    FuzzHelper f(data, size);
   38|    372|    f.run();
   39|    372|    return 0;
   40|    372|}
_ZN10FuzzHelperC2EPKhm:
   11|    372|        data(data),
   12|    372|        size(size)
   13|    372|    {
   14|    372|    }
_ZN10FuzzHelper3runEv:
   18|    372|    {
   19|    372|        Pl_Discard discard;
   20|    372|        Pl_LZWDecoder p("decode", &discard, false);
   21|    372|        try {
   22|    372|            p.write(data, size);
   23|    372|            p.finish();
   24|    372|        } catch (std::runtime_error const& e) {
   25|     51|            std::cerr << "runtime_error: " << e.what() << '\n';
   26|     51|        }
   27|    372|    }

_ZN8PipelineD2Ev:
   52|    744|    virtual ~Pipeline() = default;
_ZNK8Pipeline4nextEv:
  103|   870k|    {
  104|   870k|        return next_;
  105|   870k|    }

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

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

_ZN6BufferC2Em:
   38|   868k|    m(std::make_unique<Members>(std::string(size, '\0')))
   39|   868k|{
   40|   868k|}
_ZN6BufferC2EOS_:
   58|  1.10M|    m(std::move(rhs.m))
   59|  1.10M|{
   60|  1.10M|}
_ZN6BufferD2Ev:
   69|  1.97M|Buffer::~Buffer() = default;
_ZNK6Buffer7getSizeEv:
   73|  50.7k|{
   74|  50.7k|    return m->size;
   75|  50.7k|}
_ZN6Buffer9getBufferEv:
   85|   944k|{
   86|   944k|    return reinterpret_cast<unsigned char*>(m->buf);
   87|   944k|}
_ZN6Buffer7MembersD2Ev:
   24|   868k|    ~Members() = default;
_ZN6Buffer7MembersC2EONSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
   18|   868k|        str(std::move(content)),
   19|   868k|        size(str.size()),
   20|   868k|        buf(str.data())
   21|   868k|    {
   22|   868k|    }

_ZN8PipelineC2EPKcPS_:
   11|    744|    identifier(identifier),
   12|    744|    next_(next)
   13|    744|{
   14|    744|}

_ZN10Pl_DiscardC2Ev:
    9|    372|    Pipeline("discard", nullptr)
   10|    372|{
   11|    372|}
_ZN10Pl_DiscardD2Ev:
   14|    372|Pl_Discard::~Pl_Discard() = default;
_ZN10Pl_Discard5writeEPKhm:
   18|   870k|{
   19|   870k|}
_ZN10Pl_Discard6finishEv:
   23|    321|{
   24|    321|}

_ZN13Pl_LZWDecoderC2EPKcP8Pipelineb:
   12|    372|    Pipeline(identifier, next),
   13|    372|    code_change_delta(early_code_change)
   14|    372|{
   15|    372|    util::assertion(next, "Attempt to create Pl_LZWDecoder with nullptr as next");
   16|    372|}
_ZN13Pl_LZWDecoder5writeEPKhm:
   20|    372|{
   21|  1.11M|    for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (21:24): [True: 1.11M, False: 372]
  ------------------
   22|  1.11M|        buf[next_char_++] = bytes[i];
   23|  1.11M|        if (next_char_ == 3) {
  ------------------
  |  Branch (23:13): [True: 371k, False: 743k]
  ------------------
   24|   371k|            next_char_ = 0;
   25|   371k|        }
   26|  1.11M|        bits_available += 8;
   27|  1.11M|        if (bits_available >= code_size) {
  ------------------
  |  Branch (27:13): [True: 872k, False: 241k]
  ------------------
   28|   872k|            sendNextCode();
   29|   872k|        }
   30|  1.11M|    }
   31|    372|}
_ZN13Pl_LZWDecoder6finishEv:
   35|    321|{
   36|    321|    next()->finish();
   37|    321|}
_ZN13Pl_LZWDecoder12sendNextCodeEv:
   41|   872k|{
   42|   872k|    unsigned int high = byte_pos;
   43|   872k|    unsigned int med = (byte_pos + 1) % 3;
   44|   872k|    unsigned int low = (byte_pos + 2) % 3;
   45|       |
   46|   872k|    unsigned int bits_from_high = 8 - bit_pos;
   47|   872k|    unsigned int bits_from_med = code_size - bits_from_high;
   48|   872k|    unsigned int bits_from_low = 0;
   49|   872k|    if (bits_from_med > 8) {
  ------------------
  |  Branch (49:9): [True: 153k, False: 719k]
  ------------------
   50|   153k|        bits_from_low = bits_from_med - 8;
   51|   153k|        bits_from_med = 8;
   52|   153k|    }
   53|   872k|    unsigned int high_mask = (1U << bits_from_high) - 1U;
   54|   872k|    unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U);
   55|   872k|    unsigned int low_mask = 0xff - ((1U << (8 - bits_from_low)) - 1U);
   56|   872k|    unsigned int code = 0;
   57|   872k|    code += (buf[high] & high_mask) << bits_from_med;
   58|   872k|    code += ((buf[med] & med_mask) >> (8 - bits_from_med));
   59|   872k|    if (bits_from_low) {
  ------------------
  |  Branch (59:9): [True: 153k, False: 719k]
  ------------------
   60|   153k|        code <<= bits_from_low;
   61|   153k|        code += ((buf[low] & low_mask) >> (8 - bits_from_low));
   62|   153k|        byte_pos = low;
   63|   153k|        bit_pos = bits_from_low;
   64|   719k|    } else {
   65|   719k|        byte_pos = med;
   66|   719k|        bit_pos = bits_from_med;
   67|   719k|    }
   68|   872k|    if (bit_pos == 8) {
  ------------------
  |  Branch (68:9): [True: 87.9k, False: 784k]
  ------------------
   69|  87.9k|        bit_pos = 0;
   70|  87.9k|        ++byte_pos;
   71|  87.9k|        byte_pos %= 3;
   72|  87.9k|    }
   73|   872k|    bits_available -= code_size;
   74|       |
   75|   872k|    handleCode(code);
   76|   872k|}
_ZN13Pl_LZWDecoder12getFirstCharEj:
   80|  25.4k|{
   81|  25.4k|    if (code < 256) {
  ------------------
  |  Branch (81:9): [True: 452, False: 25.0k]
  ------------------
   82|    452|        return static_cast<unsigned char>(code);
   83|    452|    }
   84|  25.0k|    util::no_ci_rt_error_if(
   85|  25.0k|        code <= 257,
   86|  25.0k|        "Pl_LZWDecoder::getFirstChar called with invalid code (" + std::to_string(code) + ")");
   87|       |
   88|  25.0k|    unsigned int idx = code - 258;
   89|  25.0k|    util::no_ci_rt_error_if(idx >= table.size(), "Pl_LZWDecoder::getFirstChar: table overflow");
   90|  25.0k|    Buffer& b = table.at(idx);
   91|  25.0k|    return b.getBuffer()[0];
   92|  25.4k|}
_ZN13Pl_LZWDecoder10addToTableEh:
   96|   868k|{
   97|   868k|    unsigned int last_size = 0;
   98|   868k|    unsigned char const* last_data = nullptr;
   99|   868k|    unsigned char tmp[1];
  100|       |
  101|   868k|    if (last_code < 256) {
  ------------------
  |  Branch (101:9): [True: 843k, False: 25.2k]
  ------------------
  102|   843k|        tmp[0] = static_cast<unsigned char>(last_code);
  103|   843k|        last_data = tmp;
  104|   843k|        last_size = 1;
  105|   843k|    } else {
  106|  25.2k|        util::no_ci_rt_error_if(
  107|  25.2k|            last_code <= 257,
  108|  25.2k|            "Pl_LZWDecoder::addToTable called with invalid code (" + std::to_string(last_code) +
  109|  25.2k|                ")");
  110|  25.2k|        unsigned int idx = last_code - 258;
  111|  25.2k|        util::no_ci_rt_error_if(idx >= table.size(), "Pl_LZWDecoder::addToTable: table overflow");
  112|  25.2k|        Buffer& b = table.at(idx);
  113|  25.2k|        last_data = b.getBuffer();
  114|  25.2k|        last_size = QIntC::to_uint(b.getSize());
  115|  25.2k|    }
  116|       |
  117|   868k|    Buffer entry(1 + last_size);
  118|   868k|    unsigned char* new_data = entry.getBuffer();
  119|   868k|    memcpy(new_data, last_data, last_size);
  120|   868k|    new_data[last_size] = c;
  121|   868k|    table.push_back(std::move(entry));
  122|   868k|}
_ZN13Pl_LZWDecoder10handleCodeEj:
  126|   872k|{
  127|   872k|    if (eod) {
  ------------------
  |  Branch (127:9): [True: 563, False: 872k]
  ------------------
  128|    563|        return;
  129|    563|    }
  130|       |
  131|   872k|    if (code == 256) {
  ------------------
  |  Branch (131:9): [True: 1.75k, False: 870k]
  ------------------
  132|  1.75k|        if (!table.empty()) {
  ------------------
  |  Branch (132:13): [True: 1.00k, False: 743]
  ------------------
  133|  1.00k|            QTC::TC("libtests", "Pl_LZWDecoder intermediate reset");
  134|  1.00k|        }
  135|  1.75k|        table.clear();
  136|  1.75k|        code_size = 9;
  137|   870k|    } else if (code == 257) {
  ------------------
  |  Branch (137:16): [True: 17, False: 870k]
  ------------------
  138|     17|        eod = true;
  139|   870k|    } else {
  140|   870k|        if (last_code != 256) {
  ------------------
  |  Branch (140:13): [True: 868k, False: 1.57k]
  ------------------
  141|       |            // Add to the table from last time.  New table entry would be what we read last plus the
  142|       |            // first character of what we're reading now.
  143|   868k|            unsigned char next_c = '\0';
  144|   868k|            unsigned int table_size = QIntC::to_uint(table.size());
  145|   868k|            if (code < 256) {
  ------------------
  |  Branch (145:17): [True: 843k, False: 25.5k]
  ------------------
  146|       |                // just read < 256; last time's next_c was code
  147|   843k|                next_c = static_cast<unsigned char>(code);
  148|   843k|            } else if (code > 257) {
  ------------------
  |  Branch (148:24): [True: 25.5k, False: 0]
  ------------------
  149|  25.5k|                size_t idx = code - 258;
  150|  25.5k|                if (idx > table_size) {
  ------------------
  |  Branch (150:21): [True: 38, False: 25.4k]
  ------------------
  151|     38|                    throw std::runtime_error("LZWDecoder: bad code received");
  152|  25.4k|                } else if (idx == table_size) {
  ------------------
  |  Branch (152:28): [True: 2.58k, False: 22.8k]
  ------------------
  153|       |                    // The encoder would have just created this entry, so the first character of
  154|       |                    // this entry would have been the same as the first character of the last entry.
  155|  2.58k|                    next_c = getFirstChar(last_code);
  156|  22.8k|                } else {
  157|  22.8k|                    next_c = getFirstChar(code);
  158|  22.8k|                }
  159|  25.5k|            }
  160|   868k|            unsigned int new_idx = 258 + table_size;
  161|   868k|            util::no_ci_rt_error_if(new_idx == 4096, "LZWDecoder: table full");
  162|   868k|            addToTable(next_c);
  163|   868k|            unsigned int change_idx = new_idx + code_change_delta;
  164|   868k|            if (change_idx == 511 || change_idx == 1023 || change_idx == 2047) {
  ------------------
  |  Branch (164:17): [True: 789, False: 868k]
  |  Branch (164:38): [True: 540, False: 867k]
  |  Branch (164:60): [True: 309, False: 867k]
  ------------------
  165|  1.63k|                ++code_size;
  166|  1.63k|            }
  167|   868k|        }
  168|       |
  169|   870k|        if (code < 256) {
  ------------------
  |  Branch (169:13): [True: 844k, False: 25.4k]
  ------------------
  170|   844k|            auto ch = static_cast<unsigned char>(code);
  171|   844k|            next()->write(&ch, 1);
  172|   844k|        } else {
  173|  25.4k|            unsigned int idx = code - 258;
  174|  25.4k|            if (idx >= table.size()) {
  ------------------
  |  Branch (174:17): [True: 12, False: 25.4k]
  ------------------
  175|     12|                throw std::runtime_error("Pl_LZWDecoder::handleCode: table overflow");
  176|     12|            }
  177|  25.4k|            Buffer& b = table.at(idx);
  178|  25.4k|            next()->write(b.getBuffer(), b.getSize());
  179|  25.4k|        }
  180|   870k|    }
  181|       |
  182|   872k|    last_code = code;
  183|   872k|}

_ZN13Pl_LZWDecoderD2Ev:
   13|    372|    ~Pl_LZWDecoder() final = default;

_ZN4qpdf4util9assertionIRA53_KcEEvbOT_:
   27|    372|    {
   28|    372|        if (!cond) {
  ------------------
  |  Branch (28:13): [True: 0, False: 372]
  ------------------
   29|      0|            throw std::logic_error(std::forward<T>(msg));
   30|      0|        }
   31|    372|    }
_ZN4qpdf4util17no_ci_rt_error_ifINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEvbOT_:
   48|  50.2k|    {
   49|  50.2k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 50.2k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  50.2k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA44_KcEEvbOT_:
   48|  25.0k|    {
   49|  25.0k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 25.0k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  25.0k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA42_KcEEvbOT_:
   48|  25.2k|    {
   49|  25.2k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 25.2k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  25.2k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA23_KcEEvbOT_:
   48|   868k|    {
   49|   868k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 1, False: 868k]
  ------------------
   50|      1|            throw std::runtime_error(std::forward<T>(msg));
   51|      1|        }
   52|   868k|    }

