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

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

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

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

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

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

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

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

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

_ZN4qpdf4util9assertionIRA53_KcEEvbOT_:
   29|    373|    {
   30|    373|        if (!cond) {
  ------------------
  |  Branch (30:13): [True: 0, False: 373]
  ------------------
   31|      0|            throw std::logic_error(std::forward<T>(msg));
   32|      0|        }
   33|    373|    }
_ZN4qpdf4util17no_ci_rt_error_ifINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEvbOT_:
   50|  47.8k|    {
   51|  47.8k|        if (cond) {
  ------------------
  |  Branch (51:13): [True: 0, False: 47.8k]
  ------------------
   52|      0|            throw std::runtime_error(std::forward<T>(msg));
   53|      0|        }
   54|  47.8k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA44_KcEEvbOT_:
   50|  23.7k|    {
   51|  23.7k|        if (cond) {
  ------------------
  |  Branch (51:13): [True: 0, False: 23.7k]
  ------------------
   52|      0|            throw std::runtime_error(std::forward<T>(msg));
   53|      0|        }
   54|  23.7k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA42_KcEEvbOT_:
   50|  24.0k|    {
   51|  24.0k|        if (cond) {
  ------------------
  |  Branch (51:13): [True: 0, False: 24.0k]
  ------------------
   52|      0|            throw std::runtime_error(std::forward<T>(msg));
   53|      0|        }
   54|  24.0k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA23_KcEEvbOT_:
   50|   955k|    {
   51|   955k|        if (cond) {
  ------------------
  |  Branch (51:13): [True: 2, False: 955k]
  ------------------
   52|      2|            throw std::runtime_error(std::forward<T>(msg));
   53|      2|        }
   54|   955k|    }

