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

_ZN8PipelineD2Ev:
   52|    794|    virtual ~Pipeline() = default;
_ZNK8Pipeline4nextEv:
  103|  1.09M|    {
  104|  1.09M|        return next_;
  105|  1.09M|    }

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

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

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

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

_ZN10Pl_DiscardC2Ev:
    9|    397|    Pipeline("discard", nullptr)
   10|    397|{
   11|    397|}
_ZN10Pl_DiscardD2Ev:
   14|    397|Pl_Discard::~Pl_Discard() = default;
_ZN10Pl_Discard5writeEPKhm:
   18|  1.09M|{
   19|  1.09M|}
_ZN10Pl_Discard6finishEv:
   23|    344|{
   24|    344|}

_ZN13Pl_LZWDecoderC2EPKcP8Pipelineb:
   12|    397|    Pipeline(identifier, next),
   13|    397|    code_change_delta(early_code_change)
   14|    397|{
   15|    397|    util::assertion(next, "Attempt to create Pl_LZWDecoder with nullptr as next");
   16|    397|}
_ZN13Pl_LZWDecoder5writeEPKhm:
   20|    397|{
   21|  1.40M|    for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (21:24): [True: 1.40M, False: 397]
  ------------------
   22|  1.40M|        buf[next_char_++] = bytes[i];
   23|  1.40M|        if (next_char_ == 3) {
  ------------------
  |  Branch (23:13): [True: 467k, False: 935k]
  ------------------
   24|   467k|            next_char_ = 0;
   25|   467k|        }
   26|  1.40M|        bits_available += 8;
   27|  1.40M|        if (bits_available >= code_size) {
  ------------------
  |  Branch (27:13): [True: 1.09M, False: 308k]
  ------------------
   28|  1.09M|            sendNextCode();
   29|  1.09M|        }
   30|  1.40M|    }
   31|    397|}
_ZN13Pl_LZWDecoder6finishEv:
   35|    344|{
   36|    344|    next()->finish();
   37|    344|}
_ZN13Pl_LZWDecoder12sendNextCodeEv:
   41|  1.09M|{
   42|  1.09M|    unsigned int high = byte_pos;
   43|  1.09M|    unsigned int med = (byte_pos + 1) % 3;
   44|  1.09M|    unsigned int low = (byte_pos + 2) % 3;
   45|       |
   46|  1.09M|    unsigned int bits_from_high = 8 - bit_pos;
   47|  1.09M|    unsigned int bits_from_med = code_size - bits_from_high;
   48|  1.09M|    unsigned int bits_from_low = 0;
   49|  1.09M|    if (bits_from_med > 8) {
  ------------------
  |  Branch (49:9): [True: 220k, False: 874k]
  ------------------
   50|   220k|        bits_from_low = bits_from_med - 8;
   51|   220k|        bits_from_med = 8;
   52|   220k|    }
   53|  1.09M|    unsigned int high_mask = (1U << bits_from_high) - 1U;
   54|  1.09M|    unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U);
   55|  1.09M|    unsigned int low_mask = 0xff - ((1U << (8 - bits_from_low)) - 1U);
   56|  1.09M|    unsigned int code = 0;
   57|  1.09M|    code += (buf[high] & high_mask) << bits_from_med;
   58|  1.09M|    code += ((buf[med] & med_mask) >> (8 - bits_from_med));
   59|  1.09M|    if (bits_from_low) {
  ------------------
  |  Branch (59:9): [True: 220k, False: 874k]
  ------------------
   60|   220k|        code <<= bits_from_low;
   61|   220k|        code += ((buf[low] & low_mask) >> (8 - bits_from_low));
   62|   220k|        byte_pos = low;
   63|   220k|        bit_pos = bits_from_low;
   64|   874k|    } else {
   65|   874k|        byte_pos = med;
   66|   874k|        bit_pos = bits_from_med;
   67|   874k|    }
   68|  1.09M|    if (bit_pos == 8) {
  ------------------
  |  Branch (68:9): [True: 87.4k, False: 1.00M]
  ------------------
   69|  87.4k|        bit_pos = 0;
   70|  87.4k|        ++byte_pos;
   71|  87.4k|        byte_pos %= 3;
   72|  87.4k|    }
   73|  1.09M|    bits_available -= code_size;
   74|       |
   75|  1.09M|    handleCode(code);
   76|  1.09M|}
_ZN13Pl_LZWDecoder12getFirstCharEj:
   80|  19.0k|{
   81|  19.0k|    if (code < 256) {
  ------------------
  |  Branch (81:9): [True: 632, False: 18.3k]
  ------------------
   82|    632|        return static_cast<unsigned char>(code);
   83|    632|    }
   84|  18.3k|    util::no_ci_rt_error_if(
   85|  18.3k|        code <= 257,
   86|  18.3k|        "Pl_LZWDecoder::getFirstChar called with invalid code (" + std::to_string(code) + ")");
   87|       |
   88|  18.3k|    unsigned int idx = code - 258;
   89|  18.3k|    util::no_ci_rt_error_if(idx >= table.size(), "Pl_LZWDecoder::getFirstChar: table overflow");
   90|  18.3k|    Buffer& b = table.at(idx);
   91|  18.3k|    return b.getBuffer()[0];
   92|  19.0k|}
_ZN13Pl_LZWDecoder10addToTableEh:
   96|  1.08M|{
   97|  1.08M|    unsigned int last_size = 0;
   98|  1.08M|    unsigned char const* last_data = nullptr;
   99|  1.08M|    unsigned char tmp[1];
  100|       |
  101|  1.08M|    if (last_code < 256) {
  ------------------
  |  Branch (101:9): [True: 1.06M, False: 18.8k]
  ------------------
  102|  1.06M|        tmp[0] = static_cast<unsigned char>(last_code);
  103|  1.06M|        last_data = tmp;
  104|  1.06M|        last_size = 1;
  105|  1.06M|    } else {
  106|  18.8k|        util::no_ci_rt_error_if(
  107|  18.8k|            last_code <= 257,
  108|  18.8k|            "Pl_LZWDecoder::addToTable called with invalid code (" + std::to_string(last_code) +
  109|  18.8k|                ")");
  110|  18.8k|        unsigned int idx = last_code - 258;
  111|  18.8k|        util::no_ci_rt_error_if(idx >= table.size(), "Pl_LZWDecoder::addToTable: table overflow");
  112|  18.8k|        Buffer& b = table.at(idx);
  113|  18.8k|        last_data = b.getBuffer();
  114|  18.8k|        last_size = QIntC::to_uint(b.getSize());
  115|  18.8k|    }
  116|       |
  117|  1.08M|    Buffer entry(1 + last_size);
  118|  1.08M|    unsigned char* new_data = entry.getBuffer();
  119|  1.08M|    memcpy(new_data, last_data, last_size);
  120|  1.08M|    new_data[last_size] = c;
  121|  1.08M|    table.push_back(std::move(entry));
  122|  1.08M|}
_ZN13Pl_LZWDecoder10handleCodeEj:
  126|  1.09M|{
  127|  1.09M|    if (eod) {
  ------------------
  |  Branch (127:9): [True: 1.27k, False: 1.09M]
  ------------------
  128|  1.27k|        return;
  129|  1.27k|    }
  130|       |
  131|  1.09M|    if (code == 256) {
  ------------------
  |  Branch (131:9): [True: 2.45k, False: 1.09M]
  ------------------
  132|  2.45k|        if (!table.empty()) {
  ------------------
  |  Branch (132:13): [True: 1.66k, False: 792]
  ------------------
  133|  1.66k|            QTC::TC("libtests", "Pl_LZWDecoder intermediate reset");
  134|  1.66k|        }
  135|  2.45k|        table.clear();
  136|  2.45k|        code_size = 9;
  137|  1.09M|    } else if (code == 257) {
  ------------------
  |  Branch (137:16): [True: 20, False: 1.09M]
  ------------------
  138|     20|        eod = true;
  139|  1.09M|    } else {
  140|  1.09M|        if (last_code != 256) {
  ------------------
  |  Branch (140:13): [True: 1.08M, False: 2.21k]
  ------------------
  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|  1.08M|            unsigned char next_c = '\0';
  144|  1.08M|            unsigned int table_size = QIntC::to_uint(table.size());
  145|  1.08M|            if (code < 256) {
  ------------------
  |  Branch (145:17): [True: 1.06M, False: 19.0k]
  ------------------
  146|       |                // just read < 256; last time's next_c was code
  147|  1.06M|                next_c = static_cast<unsigned char>(code);
  148|  1.06M|            } else if (code > 257) {
  ------------------
  |  Branch (148:24): [True: 19.0k, False: 0]
  ------------------
  149|  19.0k|                size_t idx = code - 258;
  150|  19.0k|                if (idx > table_size) {
  ------------------
  |  Branch (150:21): [True: 38, False: 19.0k]
  ------------------
  151|     38|                    throw std::runtime_error("LZWDecoder: bad code received");
  152|  19.0k|                } else if (idx == table_size) {
  ------------------
  |  Branch (152:28): [True: 2.88k, False: 16.1k]
  ------------------
  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.88k|                    next_c = getFirstChar(last_code);
  156|  16.1k|                } else {
  157|  16.1k|                    next_c = getFirstChar(code);
  158|  16.1k|                }
  159|  19.0k|            }
  160|  1.08M|            unsigned int new_idx = 258 + table_size;
  161|  1.08M|            util::no_ci_rt_error_if(new_idx == 4096, "LZWDecoder: table full");
  162|  1.08M|            addToTable(next_c);
  163|  1.08M|            unsigned int change_idx = new_idx + code_change_delta;
  164|  1.08M|            if (change_idx == 511 || change_idx == 1023 || change_idx == 2047) {
  ------------------
  |  Branch (164:17): [True: 928, False: 1.08M]
  |  Branch (164:38): [True: 676, False: 1.08M]
  |  Branch (164:60): [True: 391, False: 1.08M]
  ------------------
  165|  1.99k|                ++code_size;
  166|  1.99k|            }
  167|  1.08M|        }
  168|       |
  169|  1.09M|        if (code < 256) {
  ------------------
  |  Branch (169:13): [True: 1.07M, False: 19.0k]
  ------------------
  170|  1.07M|            auto ch = static_cast<unsigned char>(code);
  171|  1.07M|            next()->write(&ch, 1);
  172|  1.07M|        } else {
  173|  19.0k|            unsigned int idx = code - 258;
  174|  19.0k|            if (idx >= table.size()) {
  ------------------
  |  Branch (174:17): [True: 11, False: 19.0k]
  ------------------
  175|     11|                throw std::runtime_error("Pl_LZWDecoder::handleCode: table overflow");
  176|     11|            }
  177|  19.0k|            Buffer& b = table.at(idx);
  178|  19.0k|            next()->write(b.getBuffer(), b.getSize());
  179|  19.0k|        }
  180|  1.09M|    }
  181|       |
  182|  1.09M|    last_code = code;
  183|  1.09M|}

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

_ZN4qpdf4util9assertionIRA53_KcEEvbOT_:
   27|    397|    {
   28|    397|        if (!cond) {
  ------------------
  |  Branch (28:13): [True: 0, False: 397]
  ------------------
   29|      0|            throw std::logic_error(std::forward<T>(msg));
   30|      0|        }
   31|    397|    }
_ZN4qpdf4util17no_ci_rt_error_ifINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEvbOT_:
   48|  37.2k|    {
   49|  37.2k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 37.2k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  37.2k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA44_KcEEvbOT_:
   48|  18.3k|    {
   49|  18.3k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 18.3k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  18.3k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA42_KcEEvbOT_:
   48|  18.8k|    {
   49|  18.8k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 18.8k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  18.8k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA23_KcEEvbOT_:
   48|  1.08M|    {
   49|  1.08M|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 4, False: 1.08M]
  ------------------
   50|      4|            throw std::runtime_error(std::forward<T>(msg));
   51|      4|        }
   52|  1.08M|    }

