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

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

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

_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|   891k|    m(std::make_unique<Members>(std::string(size, '\0')))
   39|   891k|{
   40|   891k|}
_ZN6BufferC2EOS_:
   58|  1.13M|    m(std::move(rhs.m))
   59|  1.13M|{
   60|  1.13M|}
_ZN6BufferD2Ev:
   69|  2.02M|Buffer::~Buffer() = default;
_ZNK6Buffer7getSizeEv:
   73|  49.1k|{
   74|  49.1k|    return m->size;
   75|  49.1k|}
_ZN6Buffer9getBufferEv:
   85|   965k|{
   86|   965k|    return reinterpret_cast<unsigned char*>(m->buf);
   87|   965k|}
_ZN6Buffer7MembersD2Ev:
   24|   891k|    ~Members() = default;
_ZN6Buffer7MembersC2EONSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
   18|   891k|        str(std::move(content)),
   19|   891k|        size(str.size()),
   20|   891k|        buf(str.data())
   21|   891k|    {
   22|   891k|    }

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

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

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

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

_ZN4qpdf4util9assertionIRA53_KcEEvbOT_:
   27|    374|    {
   28|    374|        if (!cond) {
  ------------------
  |  Branch (28:13): [True: 0, False: 374]
  ------------------
   29|      0|            throw std::logic_error(std::forward<T>(msg));
   30|      0|        }
   31|    374|    }
_ZN4qpdf4util17no_ci_rt_error_ifINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEvbOT_:
   48|  48.7k|    {
   49|  48.7k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 48.7k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  48.7k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA44_KcEEvbOT_:
   48|  24.2k|    {
   49|  24.2k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 24.2k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  24.2k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA42_KcEEvbOT_:
   48|  24.4k|    {
   49|  24.4k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 24.4k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  24.4k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA23_KcEEvbOT_:
   48|   891k|    {
   49|   891k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 2, False: 891k]
  ------------------
   50|      2|            throw std::runtime_error(std::forward<T>(msg));
   51|      2|        }
   52|   891k|    }

