  595 |         case EXLEN:
  596 |             if (state->flags & 0x0400) {
  597 |                 NEEDBITS(16);
  598 |                 state->length = (unsigned)(hold);
  599 |                 if (state->head != Z_NULL)
  600 |                     state->head->extra_len = (unsigned)hold;
  601 |                 if ((state->flags & 0x0200) && (state->wrap & 4))
  602 |                     CRC2(state->check, hold);
  603 |                 INITBITS();
  604 |             }
  605 |             else if (state->head != Z_NULL)
  606 |                 state->head->extra = Z_NULL;
  607 |             state->mode = EXTRA;
  608 |                 /* fallthrough */
  609 |         case EXTRA:
  610 |             if (state->flags & 0x0400) {
  611 |                 copy = state->length;
  612 |                 if (copy > have) copy = have;
  613 |                 if (copy) {
  614 |                     if (state->head != Z_NULL &&
  615 |                         state->head->extra != Z_NULL &&
  616 |                         (len = state->head->extra_len - state->length) <
  617 |                             state->head->extra_max) {
  618 |                         zmemcpy(state->head->extra + len, next,
  619 |                                 len + copy > state->head->extra_max ?
  620 |                                 state->head->extra_max - len : copy);
  621 |                     }
  622 |                     if ((state->flags & 0x0200) && (state->wrap & 4))
  623 |                         state->check = crc32(state->check, next, copy);
  624 |                     have -= copy;
  625 |                     next += copy;
  626 |                     state->length -= copy;
  627 |                 }
  628 |                 if (state->length) goto inf_leave;
  629 |             }
  630 |             state->length = 0;
  631 |             state->mode = NAME;
  632 |                 /* fallthrough */
  633 |         case NAME:
  634 |             if (state->flags & 0x0800) {
  635 |                 if (have == 0) goto inf_leave;
  636 |                 copy = 0;
  637 |                 do {
  638 |                     len = (unsigned)(next[copy++]);
  639 |                     if (state->head != Z_NULL &&
  640 |                             state->head->name != Z_NULL &&
  641 |                             state->length < state->head->name_max)
  642 |                         state->head->name[state->length++] = (Bytef)len;
  643 |                 } while (len && copy < have);
  644 |                 if ((state->flags & 0x0200) && (state->wrap & 4))
  645 |                     state->check = crc32(state->check, next, copy);
  646 |                 have -= copy;
  647 |                 next += copy;
  648 |                 if (len) goto inf_leave;
  649 |             }
  650 |             else if (state->head != Z_NULL)
  651 |                 state->head->name = Z_NULL;
  652 |             state->length = 0;
  653 |             state->mode = COMMENT;
  654 |                 /* fallthrough */
  655 |         case COMMENT:
  656 |             if (state->flags & 0x1000) {
  657 |                 if (have == 0) goto inf_leave;
  658 |                 copy = 0;
  659 |                 do {
  660 |                     len = (unsigned)(next[copy++]);
  661 |                     if (state->head != Z_NULL &&
  662 |                             state->head->comment != Z_NULL &&
  663 |                             state->length < state->head->comm_max)
  664 |                         state->head->comment[state->length++] = (Bytef)len;
  665 |                 } while (len && copy < have);
  666 |                 if ((state->flags & 0x0200) && (state->wrap & 4))
  667 |                     state->check = crc32(state->check, next, copy);
  668 |                 have -= copy;
  669 |                 next += copy;
  670 |                 if (len) goto inf_leave;
  671 |             }
  672 |             else if (state->head != Z_NULL)
  673 |                 state->head->comment = Z_NULL;
  674 |             state->mode = HCRC;
  675 |                 /* fallthrough */
  676 |         case HCRC:
  677 |             if (state->flags & 0x0200) {
  678 |                 NEEDBITS(16);
  679 |                 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
  680 |                     strm->msg = (z_const char *)"header crc mismatch";
  681 |                     state->mode = BAD;
  682 |                     break;
  683 |                 }
  684 |                 INITBITS();
  685 |             }
  686 |             if (state->head != Z_NULL) {
  687 |                 state->head->hcrc = (int)((state->flags >> 9) & 1);
  688 |                 state->head->done = 1;
  689 |             }
  690 |             strm->adler = state->check = crc32(0L, Z_NULL, 0);
  691 |             state->mode = TYPE;
  692 |             break;
  693 | #endif
  694 |         case DICTID:
> 695 |             NEEDBITS(32);
  696 |             strm->adler = state->check = ZSWAP32(hold);
  697 |             INITBITS();
  698 |             state->mode = DICT;
  699 |                 /* fallthrough */
  700 |         case DICT:
  701 |             if (state->havedict == 0) {
  702 |                 RESTORE();
  703 |                 return Z_NEED_DICT;
  704 |             }
  705 |             strm->adler = state->check = adler32(0L, Z_NULL, 0);
  706 |             state->mode = TYPE;
  707 |                 /* fallthrough */
  708 |         case TYPE:
  709 |             if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
  710 |                 /* fallthrough */
  711 |         case TYPEDO:
  712 |             if (state->last) {
  713 |                 BYTEBITS();
  714 |                 state->mode = CHECK;
  715 |                 break;
  716 |             }
  717 |             NEEDBITS(3);
  718 |             state->last = BITS(1);
  719 |             DROPBITS(1);
  720 |             switch (BITS(2)) {
  721 |             case 0:                             /* stored block */
  722 |                 Tracev((stderr, "inflate:     stored block%s\n",
  723 |                         state->last ? " (last)" : ""));
  724 |                 state->mode = STORED;
  725 |                 break;
  726 |             case 1:                             /* fixed block */
  727 |                 inflate_fixed(state);
  728 |                 Tracev((stderr, "inflate:     fixed codes block%s\n",
  729 |                         state->last ? " (last)" : ""));
  730 |                 state->mode = LEN_;             /* decode codes */
  731 |                 if (flush == Z_TREES) {
  732 |                     DROPBITS(2);
  733 |                     goto inf_leave;
  734 |                 }
  735 |                 break;
  736 |             case 2:                             /* dynamic block */
  737 |                 Tracev((stderr, "inflate:     dynamic codes block%s\n",
  738 |                         state->last ? " (last)" : ""));
  739 |                 state->mode = TABLE;
  740 |                 break;
  741 |             default:
  742 |                 strm->msg = (z_const char *)"invalid block type";
  743 |                 state->mode = BAD;
  744 |             }
  745 |             DROPBITS(2);
  746 |             break;
  747 |         case STORED:
  748 |             BYTEBITS();                         /* go to byte boundary */
  749 |             NEEDBITS(32);
  750 |             if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  751 |                 strm->msg = (z_const char *)"invalid stored block lengths";
  752 |                 state->mode = BAD;
  753 |                 break;
  754 |             }
  755 |             state->length = (unsigned)hold & 0xffff;
  756 |             Tracev((stderr, "inflate:       stored length %u\n",
  757 |                     state->length));
  758 |             INITBITS();
  759 |             state->mode = COPY_;
  760 |             if (flush == Z_TREES) goto inf_leave;
  761 |                 /* fallthrough */
  762 |         case COPY_:
  763 |             state->mode = COPY;
  764 |                 /* fallthrough */
  765 |         case COPY:
  766 |             copy = state->length;
  767 |             if (copy) {
  768 |                 if (copy > have) copy = have;
  769 |                 if (copy > left) copy = left;
  770 |                 if (copy == 0) goto inf_leave;
  771 |                 zmemcpy(put, next, copy);
  772 |                 have -= copy;
  773 |                 next += copy;
  774 |                 left -= copy;
  775 |                 put += copy;
  776 |                 state->length -= copy;
  777 |                 break;
  778 |             }
  779 |             Tracev((stderr, "inflate:       stored end\n"));
  780 |             state->mode = TYPE;
  781 |             break;
  782 |         case TABLE:
  783 |             NEEDBITS(14);
  784 |             state->nlen = BITS(5) + 257;
  785 |             DROPBITS(5);
  786 |             state->ndist = BITS(5) + 1;
  787 |             DROPBITS(5);
  788 |             state->ncode = BITS(4) + 4;
  789 |             DROPBITS(4);
  790 | #ifndef PKZIP_BUG_WORKAROUND
  791 |             if (state->nlen > 286 || state->ndist > 30) {
  792 |                 strm->msg = (z_const char *)
  793 |                     "too many length or distance symbols";
  794 |                 state->mode = BAD;
  795 |                 break;

Reach line at /src/zlib/inflate.c:695 (observed count 27).


    1 | /* adler32.c -- compute the Adler-32 checksum of a data stream
    2 |  * Copyright (C) 1995-2011, 2016 Mark Adler
    3 |  * For conditions of distribution and use, see copyright notice in zlib.h
    4 |  */
    5 |
    6 | /* @(#) $Id$ */
    7 |
    8 | #include "zutil.h"
    9 |
   10 | #define BASE 65521U     /* largest prime smaller than 65536 */
   11 | #define NMAX 5552
   12 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
   13 |
   14 | #define DO1(buf,i)  {adler += (buf)[i]; sum2 += adler;}
   15 | #define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
   16 | #define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
   17 | #define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
   18 | #define DO16(buf)   DO8(buf,0); DO8(buf,8);
   19 |
   20 | /* use NO_DIVIDE if your processor does not do division in hardware --
   21 |    try it both ways to see which is faster */
   22 | #ifdef NO_DIVIDE
   23 | /* note that this assumes BASE is 65521, where 65536 % 65521 == 15
   24 |    (thank you to John Reiser for pointing this out) */
   25 | #  define CHOP(a) \
   26 |     do { \
   27 |         unsigned long tmp = a >> 16; \
   28 |         a &= 0xffffUL; \
   29 |         a += (tmp << 4) - tmp; \
   30 |     } while (0)
   31 | #  define MOD28(a) \
   32 |     do { \
   33 |         CHOP(a); \
   34 |         if (a >= BASE) a -= BASE; \
   35 |     } while (0)
   36 | #  define MOD(a) \
   37 |     do { \
   38 |         CHOP(a); \
   39 |         MOD28(a); \
   40 |     } while (0)
   41 | #  define MOD63(a) \
   42 |     do { /* this assumes a is not negative */ \
   43 |         z_off64_t tmp = a >> 32; \
   44 |         a &= 0xffffffffL; \
   45 |         a += (tmp << 8) - (tmp << 5) + tmp; \
   46 |         tmp = a >> 16; \
   47 |         a &= 0xffffL; \
   48 |         a += (tmp << 4) - tmp; \
   49 |         tmp = a >> 16; \
   50 |         a &= 0xffffL; \
   51 |         a += (tmp << 4) - tmp; \
   52 |         if (a >= BASE) a -= BASE; \
   53 |     } while (0)
   54 | #else
   55 | #  define MOD(a) a %= BASE
   56 | #  define MOD28(a) a %= BASE
   57 | #  define MOD63(a) a %= BASE
   58 | #endif
   59 |
   60 | /* ========================================================================= */
   61 | uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
   62 |     unsigned long sum2;
   63 |     unsigned n;
   64 |
   65 |     /* split Adler-32 into component sums */
   66 |     sum2 = (adler >> 16) & 0xffff;
   67 |     adler &= 0xffff;
   68 |
   69 |     /* in case user likes doing a byte at a time, keep it fast */
   70 |     if (len == 1) {
   71 |         adler += buf[0];
   72 |         if (adler >= BASE)
   73 |             adler -= BASE;
>  74 |         sum2 += adler;
   75 |         if (sum2 >= BASE)
   76 |             sum2 -= BASE;
   77 |         return adler | (sum2 << 16);
   78 |     }
   79 |
   80 |     /* initial Adler-32 value (deferred check for len == 1 speed) */
   81 |     if (buf == Z_NULL)
   82 |         return 1L;
   83 |
   84 |     /* in case short lengths are provided, keep it somewhat fast */
   85 |     if (len < 16) {
   86 |         while (len--) {
   87 |             adler += *buf++;
   88 |             sum2 += adler;
   89 |         }
   90 |         if (adler >= BASE)
   91 |             adler -= BASE;
   92 |         MOD28(sum2);            /* only added so many BASE's */
   93 |         return adler | (sum2 << 16);
   94 |     }
   95 |
   96 |     /* do length NMAX blocks -- requires just one modulo operation */
   97 |     while (len >= NMAX) {
   98 |         len -= NMAX;
   99 |         n = NMAX / 16;          /* NMAX is divisible by 16 */
  100 |         do {
  101 |             DO16(buf);          /* 16 sums unrolled */
  102 |             buf += 16;
  103 |         } while (--n);
  104 |         MOD(adler);
  105 |         MOD(sum2);
  106 |     }
  107 |
  108 |     /* do remaining bytes (less than NMAX, still just one modulo) */
  109 |     if (len) {                  /* avoid modulos if none remaining */
  110 |         while (len >= 16) {
  111 |             len -= 16;
  112 |             DO16(buf);
  113 |             buf += 16;
  114 |         }
  115 |         while (len--) {
  116 |             adler += *buf++;
  117 |             sum2 += adler;
  118 |         }
  119 |         MOD(adler);
  120 |         MOD(sum2);
  121 |     }
  122 |
  123 |     /* return recombined sums */
  124 |     return adler | (sum2 << 16);
  125 | }
  126 |
  127 | /* ========================================================================= */
  128 | uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
  129 |     return adler32_z(adler, buf, len);
  130 | }
  131 |
  132 | /* ========================================================================= */
  133 | local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
  134 |     unsigned long sum1;
  135 |     unsigned long sum2;
  136 |     unsigned rem;
  137 |
  138 |     /* for negative len, return invalid adler32 as a clue for debugging */
  139 |     if (len2 < 0)
  140 |         return 0xffffffffUL;
  141 |
  142 |     /* the derivation of this formula is left as an exercise for the reader */
  143 |     MOD63(len2);                /* assumes len2 >= 0 */
  144 |     rem = (unsigned)len2;
  145 |     sum1 = adler1 & 0xffff;
  146 |     sum2 = rem * sum1;
  147 |     MOD(sum2);
  148 |     sum1 += (adler2 & 0xffff) + BASE - 1;
  149 |     sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  150 |     if (sum1 >= BASE) sum1 -= BASE;
  151 |     if (sum1 >= BASE) sum1 -= BASE;
  152 |     if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
  153 |     if (sum2 >= BASE) sum2 -= BASE;
  154 |     return sum1 | (sum2 << 16);
  155 | }
  156 |
  157 | /* ========================================================================= */
  158 | uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
  159 |     return adler32_combine_(adler1, adler2, len2);
  160 | }
  161 |
  162 | uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
  163 |     return adler32_combine_(adler1, adler2, len2);
  164 | }

Reach line at /src/zlib/adler32.c:74 (observed count 350).


  194 |     /*!
  195 |      * Returns the content of this file.
  196 |      * Call data() with care (only once per file), this data isn't cached.
  197 |      */
  198 |     [[nodiscard]] QByteArray data() const override;
  199 |
  200 |     /*!
  201 |      * This method returns QIODevice (internal class: KLimitedIODevice)
  202 |      * on top of the underlying QIODevice. This is obviously for reading only.
  203 |      *
  204 |      * WARNING: Note that the ownership of the device is being transferred to the caller,
  205 |      * who will have to delete it.
  206 |      *
  207 |      * The returned device auto-opens (in readonly mode), no need to open it.
  208 |      * Returns the QIODevice of the file
  209 |      */
  210 |     [[nodiscard]] QIODevice *createDevice() const override;
  211 |
  212 | private:
  213 |     const QByteArray m_data;
  214 |     QBuffer *m_buffer;
  215 | };
  216 |
  217 | K7ZipFileEntry::K7ZipFileEntry(K7Zip *zip,
  218 |                                const QString &name,
  219 |                                int access,
  220 |                                const QDateTime &date,
  221 |                                const QString &user,
  222 |                                const QString &group,
  223 |                                const QString &symlink,
  224 |                                qint64 pos,
  225 |                                qint64 size,
  226 |                                const QByteArray &data)
  227 |     : KArchiveFile(zip, name, access, date, user, group, symlink, pos, size)
  228 |     , m_data(data)
  229 |     , m_buffer(new QBuffer)
  230 | {
  231 |     m_buffer->setData(m_data);
  232 |     m_buffer->open(QIODevice::ReadOnly);
  233 | }
  234 |
  235 | K7ZipFileEntry::~K7ZipFileEntry()
  236 | {
  237 |     delete m_buffer;
  238 | }
  239 |
  240 | QByteArray K7ZipFileEntry::data() const
  241 | {
  242 |     return m_data.mid(position(), size());
  243 | }
  244 |
  245 | QIODevice *K7ZipFileEntry::createDevice() const
  246 | {
  247 |     return new KLimitedIODevice(m_buffer, position(), size());
  248 | }
  249 |
  250 | class FileInfo
  251 | {
  252 | public:
  253 |     FileInfo() = default;
  254 |
  255 |     QString path;
  256 |     quint64 size = 0;
  257 |     quint32 attributes = 0;
  258 |     quint32 crc = 0;
  259 |     bool attribDefined = false;
  260 |     bool crcDefined = false;
  261 |     bool hasStream = false;
  262 |     bool isDir = false;
  263 | };
  264 |
  265 | class Folder
  266 | {
  267 | public:
  268 |     class FolderInfo
  269 |     {
  270 |     public:
  271 |         FolderInfo() = default;
  272 |
  273 |         [[nodiscard]] bool isSimpleCoder() const
  274 |         {
  275 |             return (numInStreams == 1) && (numOutStreams == 1);
  276 |         }
  277 |
  278 |         int numInStreams = 0;
  279 |         int numOutStreams = 0;
  280 |         QList<unsigned char> properties;
  281 |         quint64 methodID = 0;
  282 |     };
  283 |
  284 |     Folder() = default;
  285 |
  286 |     ~Folder() = default;
  287 |
  288 |     Q_DISABLE_COPY(Folder)
  289 |
  290 |     [[nodiscard]] quint64 getUnpackSize() const
  291 |     {
  292 |         if (unpackSizes.isEmpty()) {
  293 |             return 0;
> 294 |         }
  295 |         for (qsizetype i = unpackSizes.size() - 1; i >= 0; i--) {
  296 |             if (findBindPairForOutStream(i) < 0) {
  297 |                 return unpackSizes.at(i);
  298 |             }
  299 |         }
  300 |         return 0;
  301 |     }
  302 |
  303 |     [[nodiscard]] int getNumOutStreams() const
  304 |     {
  305 |         int result = 0;
  306 |         for (const FolderInfo &folderInfo : folderInfos) {
  307 |             result += folderInfo.numOutStreams;
  308 |         }
  309 |         return result;
  310 |     }
  311 |
  312 |     [[nodiscard]] quint32 getCoderInStreamIndex(quint32 coderIndex) const
  313 |     {
  314 |         quint32 streamIndex = 0;
  315 |         for (quint32 i = 0; i < coderIndex; i++) {
  316 |             streamIndex += folderInfos.at(i).numInStreams;
  317 |         }
  318 |         return streamIndex;
  319 |     }
  320 |
  321 |     [[nodiscard]] quint32 getCoderOutStreamIndex(quint32 coderIndex) const
  322 |     {
  323 |         quint32 streamIndex = 0;
  324 |         for (quint32 i = 0; i < coderIndex; i++) {
  325 |             streamIndex += folderInfos.at(i).numOutStreams;
  326 |         }
  327 |         return streamIndex;
  328 |     }
  329 |
  330 |     [[nodiscard]] int findBindPairForInStream(size_t inStreamIndex) const
  331 |     {
  332 |         for (int i = 0; i < inIndexes.size(); i++) {
  333 |             if (inIndexes[i] == inStreamIndex) {
  334 |                 return i;
  335 |             }
  336 |         }
  337 |         return -1;
  338 |     }
  339 |
  340 |     [[nodiscard]] int findBindPairForOutStream(size_t outStreamIndex) const
  341 |     {
  342 |         for (int i = 0; i < outIndexes.size(); i++) {
  343 |             if (outIndexes[i] == outStreamIndex) {
  344 |                 return i;
  345 |             }
  346 |         }
  347 |         return -1;
  348 |     }
  349 |
  350 |     [[nodiscard]] int findPackStreamArrayIndex(size_t inStreamIndex) const
  351 |     {
  352 |         for (int i = 0; i < packedStreams.size(); i++) {
  353 |             if (packedStreams[i] == inStreamIndex) {
  354 |                 return i;
  355 |             }
  356 |         }
  357 |         return -1;
  358 |     }
  359 |
  360 |     void findInStream(quint32 streamIndex, quint32 &coderIndex, quint32 &coderStreamIndex) const
  361 |     {
  362 |         for (coderIndex = 0; coderIndex < (quint32)folderInfos.size(); coderIndex++) {
  363 |             quint32 curSize = folderInfos[coderIndex].numInStreams;
  364 |             if (streamIndex < curSize) {
  365 |                 coderStreamIndex = streamIndex;
  366 |                 return;
  367 |             }
  368 |             streamIndex -= curSize;
  369 |         }
  370 |     }
  371 |
  372 |     void findOutStream(quint32 streamIndex, quint32 &coderIndex, quint32 &coderStreamIndex) const
  373 |     {
  374 |         for (coderIndex = 0; coderIndex < (quint32)folderInfos.size(); coderIndex++) {
  375 |             quint32 curSize = folderInfos[coderIndex].numOutStreams;
  376 |             if (streamIndex < curSize) {
  377 |                 coderStreamIndex = streamIndex;
  378 |                 return;
  379 |             }
  380 |             streamIndex -= curSize;
  381 |         }
  382 |     }
  383 |
  384 |     [[nodiscard]] bool isEncrypted() const
  385 |     {
  386 |         for (qsizetype i = folderInfos.size() - 1; i >= 0; i--) {
  387 |             if (folderInfos.at(i).methodID == k_AES) {
  388 |                 return true;
  389 |             }
  390 |         }
  391 |         return false;
  392 |     }
  393 |
  394 |     // bool CheckStructure() const;

Reach line at /src/karchive/src/k7zip.cpp:294 (observed count 24).


  465 | 			for (i = 16; i < laneCount; i++) {
  466 | 				ExtrXor( i );
  467 | 			}
  468 | 		}
  469 | 	} else {
  470 | 		for (i = 0; i < laneCount; i++) {
  471 | 			ExtrXor( i );
  472 | 		}
  473 | 	}
  474 | #undef  ExtrXor
  475 | #undef  ExtrXor4
  476 | }
  477 |
  478 | #define declareABCDE \
  479 |     V256 Aba, Abe, Abi, Abo, Abu; \
  480 |     V256 Aga, Age, Agi, Ago, Agu; \
  481 |     V256 Aka, Ake, Aki, Ako, Aku; \
  482 |     V256 Ama, Ame, Ami, Amo, Amu; \
  483 |     V256 Asa, Ase, Asi, Aso, Asu; \
  484 |     V256 Bba, Bbe, Bbi, Bbo, Bbu; \
  485 |     V256 Bga, Bge, Bgi, Bgo, Bgu; \
  486 |     V256 Bka, Bke, Bki, Bko, Bku; \
  487 |     V256 Bma, Bme, Bmi, Bmo, Bmu; \
  488 |     V256 Bsa, Bse, Bsi, Bso, Bsu; \
  489 |     V256 Ca, Ce, Ci, Co, Cu; \
  490 |     V256 Ca1, Ce1, Ci1, Co1, Cu1; \
  491 |     V256 Da, De, Di, Do, Du; \
  492 |     V256 Eba, Ebe, Ebi, Ebo, Ebu; \
  493 |     V256 Ega, Ege, Egi, Ego, Egu; \
  494 |     V256 Eka, Eke, Eki, Eko, Eku; \
  495 |     V256 Ema, Eme, Emi, Emo, Emu; \
  496 |     V256 Esa, Ese, Esi, Eso, Esu; \
  497 |
  498 | #define prepareTheta \
  499 |     Ca = XOR256(Aba, XOR256(Aga, XOR256(Aka, XOR256(Ama, Asa)))); \
  500 |     Ce = XOR256(Abe, XOR256(Age, XOR256(Ake, XOR256(Ame, Ase)))); \
  501 |     Ci = XOR256(Abi, XOR256(Agi, XOR256(Aki, XOR256(Ami, Asi)))); \
  502 |     Co = XOR256(Abo, XOR256(Ago, XOR256(Ako, XOR256(Amo, Aso)))); \
  503 |     Cu = XOR256(Abu, XOR256(Agu, XOR256(Aku, XOR256(Amu, Asu)))); \
  504 |
  505 | /* --- Theta Rho Pi Chi Iota Prepare-theta */
  506 | /* --- 64-bit lanes mapped to 64-bit words */
  507 | #define thetaRhoPiChiIotaPrepareTheta(i, A, E) \
  508 |     ROL64in256(Ce1, Ce, 1); \
  509 |     Da = XOR256(Cu, Ce1); \
  510 |     ROL64in256(Ci1, Ci, 1); \
  511 |     De = XOR256(Ca, Ci1); \
  512 |     ROL64in256(Co1, Co, 1); \
  513 |     Di = XOR256(Ce, Co1); \
  514 |     ROL64in256(Cu1, Cu, 1); \
  515 |     Do = XOR256(Ci, Cu1); \
  516 |     ROL64in256(Ca1, Ca, 1); \
  517 |     Du = XOR256(Co, Ca1); \
  518 | \
  519 |     XOReq256(A##ba, Da); \
  520 |     Bba = A##ba; \
  521 |     XOReq256(A##ge, De); \
  522 |     ROL64in256(Bbe, A##ge, 44); \
  523 |     XOReq256(A##ki, Di); \
  524 |     ROL64in256(Bbi, A##ki, 43); \
  525 |     E##ba = XOR256(Bba, ANDnu256(Bbe, Bbi)); \
  526 |     XOReq256(E##ba, CONST256_64(KeccakF1600RoundConstants[i])); \
  527 |     Ca = E##ba; \
  528 |     XOReq256(A##mo, Do); \
  529 |     ROL64in256(Bbo, A##mo, 21); \
  530 |     E##be = XOR256(Bbe, ANDnu256(Bbi, Bbo)); \
  531 |     Ce = E##be; \
  532 |     XOReq256(A##su, Du); \
  533 |     ROL64in256(Bbu, A##su, 14); \
  534 |     E##bi = XOR256(Bbi, ANDnu256(Bbo, Bbu)); \
  535 |     Ci = E##bi; \
  536 |     E##bo = XOR256(Bbo, ANDnu256(Bbu, Bba)); \
  537 |     Co = E##bo; \
  538 |     E##bu = XOR256(Bbu, ANDnu256(Bba, Bbe)); \
  539 |     Cu = E##bu; \
  540 | \
  541 |     XOReq256(A##bo, Do); \
  542 |     ROL64in256(Bga, A##bo, 28); \
  543 |     XOReq256(A##gu, Du); \
  544 |     ROL64in256(Bge, A##gu, 20); \
  545 |     XOReq256(A##ka, Da); \
  546 |     ROL64in256(Bgi, A##ka, 3); \
  547 |     E##ga = XOR256(Bga, ANDnu256(Bge, Bgi)); \
  548 |     XOReq256(Ca, E##ga); \
  549 |     XOReq256(A##me, De); \
  550 |     ROL64in256(Bgo, A##me, 45); \
  551 |     E##ge = XOR256(Bge, ANDnu256(Bgi, Bgo)); \
  552 |     XOReq256(Ce, E##ge); \
  553 |     XOReq256(A##si, Di); \
  554 |     ROL64in256(Bgu, A##si, 61); \
  555 |     E##gi = XOR256(Bgi, ANDnu256(Bgo, Bgu)); \
  556 |     XOReq256(Ci, E##gi); \
  557 |     E##go = XOR256(Bgo, ANDnu256(Bgu, Bga)); \
  558 |     XOReq256(Co, E##go); \
  559 |     E##gu = XOR256(Bgu, ANDnu256(Bga, Bge)); \
  560 |     XOReq256(Cu, E##gu); \
  561 | \
  562 |     XOReq256(A##be, De); \
  563 |     ROL64in256(Bka, A##be, 1); \
  564 |     XOReq256(A##gi, Di); \
> 565 |     ROL64in256(Bke, A##gi, 6); \
  566 |     XOReq256(A##ko, Do); \
  567 |     ROL64in256(Bki, A##ko, 25); \
  568 |     E##ka = XOR256(Bka, ANDnu256(Bke, Bki)); \
  569 |     XOReq256(Ca, E##ka); \
  570 |     XOReq256(A##mu, Du); \
  571 |     ROL64in256_8(Bko, A##mu); \
  572 |     E##ke = XOR256(Bke, ANDnu256(Bki, Bko)); \
  573 |     XOReq256(Ce, E##ke); \
  574 |     XOReq256(A##sa, Da); \
  575 |     ROL64in256(Bku, A##sa, 18); \
  576 |     E##ki = XOR256(Bki, ANDnu256(Bko, Bku)); \
  577 |     XOReq256(Ci, E##ki); \
  578 |     E##ko = XOR256(Bko, ANDnu256(Bku, Bka)); \
  579 |     XOReq256(Co, E##ko); \
  580 |     E##ku = XOR256(Bku, ANDnu256(Bka, Bke)); \
  581 |     XOReq256(Cu, E##ku); \
  582 | \
  583 |     XOReq256(A##bu, Du); \
  584 |     ROL64in256(Bma, A##bu, 27); \
  585 |     XOReq256(A##ga, Da); \
  586 |     ROL64in256(Bme, A##ga, 36); \
  587 |     XOReq256(A##ke, De); \
  588 |     ROL64in256(Bmi, A##ke, 10); \
  589 |     E##ma = XOR256(Bma, ANDnu256(Bme, Bmi)); \
  590 |     XOReq256(Ca, E##ma); \
  591 |     XOReq256(A##mi, Di); \
  592 |     ROL64in256(Bmo, A##mi, 15); \
  593 |     E##me = XOR256(Bme, ANDnu256(Bmi, Bmo)); \
  594 |     XOReq256(Ce, E##me); \
  595 |     XOReq256(A##so, Do); \
  596 |     ROL64in256_56(Bmu, A##so); \
  597 |     E##mi = XOR256(Bmi, ANDnu256(Bmo, Bmu)); \
  598 |     XOReq256(Ci, E##mi); \
  599 |     E##mo = XOR256(Bmo, ANDnu256(Bmu, Bma)); \
  600 |     XOReq256(Co, E##mo); \
  601 |     E##mu = XOR256(Bmu, ANDnu256(Bma, Bme)); \
  602 |     XOReq256(Cu, E##mu); \
  603 | \
  604 |     XOReq256(A##bi, Di); \
  605 |     ROL64in256(Bsa, A##bi, 62); \
  606 |     XOReq256(A##go, Do); \
  607 |     ROL64in256(Bse, A##go, 55); \
  608 |     XOReq256(A##ku, Du); \
  609 |     ROL64in256(Bsi, A##ku, 39); \
  610 |     E##sa = XOR256(Bsa, ANDnu256(Bse, Bsi)); \
  611 |     XOReq256(Ca, E##sa); \
  612 |     XOReq256(A##ma, Da); \
  613 |     ROL64in256(Bso, A##ma, 41); \
  614 |     E##se = XOR256(Bse, ANDnu256(Bsi, Bso)); \
  615 |     XOReq256(Ce, E##se); \
  616 |     XOReq256(A##se, De); \
  617 |     ROL64in256(Bsu, A##se, 2); \
  618 |     E##si = XOR256(Bsi, ANDnu256(Bso, Bsu)); \
  619 |     XOReq256(Ci, E##si); \
  620 |     E##so = XOR256(Bso, ANDnu256(Bsu, Bsa)); \
  621 |     XOReq256(Co, E##so); \
  622 |     E##su = XOR256(Bsu, ANDnu256(Bsa, Bse)); \
  623 |     XOReq256(Cu, E##su); \
  624 | \
  625 |
  626 | /* --- Theta Rho Pi Chi Iota */
  627 | /* --- 64-bit lanes mapped to 64-bit words */
  628 | #define thetaRhoPiChiIota(i, A, E) \
  629 |     ROL64in256(Ce1, Ce, 1); \
  630 |     Da = XOR256(Cu, Ce1); \
  631 |     ROL64in256(Ci1, Ci, 1); \
  632 |     De = XOR256(Ca, Ci1); \
  633 |     ROL64in256(Co1, Co, 1); \
  634 |     Di = XOR256(Ce, Co1); \
  635 |     ROL64in256(Cu1, Cu, 1); \
  636 |     Do = XOR256(Ci, Cu1); \
  637 |     ROL64in256(Ca1, Ca, 1); \
  638 |     Du = XOR256(Co, Ca1); \
  639 | \
  640 |     XOReq256(A##ba, Da); \
  641 |     Bba = A##ba; \
  642 |     XOReq256(A##ge, De); \
  643 |     ROL64in256(Bbe, A##ge, 44); \
  644 |     XOReq256(A##ki, Di); \
  645 |     ROL64in256(Bbi, A##ki, 43); \
  646 |     E##ba = XOR256(Bba, ANDnu256(Bbe, Bbi)); \
  647 |     XOReq256(E##ba, CONST256_64(KeccakF1600RoundConstants[i])); \
  648 |     XOReq256(A##mo, Do); \
  649 |     ROL64in256(Bbo, A##mo, 21); \
  650 |     E##be = XOR256(Bbe, ANDnu256(Bbi, Bbo)); \
  651 |     XOReq256(A##su, Du); \
  652 |     ROL64in256(Bbu, A##su, 14); \
  653 |     E##bi = XOR256(Bbi, ANDnu256(Bbo, Bbu)); \
  654 |     E##bo = XOR256(Bbo, ANDnu256(Bbu, Bba)); \
  655 |     E##bu = XOR256(Bbu, ANDnu256(Bba, Bbe)); \
  656 | \
  657 |     XOReq256(A##bo, Do); \
  658 |     ROL64in256(Bga, A##bo, 28); \
  659 |     XOReq256(A##gu, Du); \
  660 |     ROL64in256(Bge, A##gu, 20); \
  661 |     XOReq256(A##ka, Da); \
  662 |     ROL64in256(Bgi, A##ka, 3); \
  663 |     E##ga = XOR256(Bga, ANDnu256(Bge, Bgi)); \
  664 |     XOReq256(A##me, De); \
  665 |     ROL64in256(Bgo, A##me, 45); \

Reach line at /src/liboqs/src/common/sha3/xkcp_low/KeccakP-1600times4/avx2/KeccakP-1600-times4-SIMD256.c:565 (observed count 89200000).


  194 |     }
  195 |   }
  196 |   else
  197 |   {
  198 | #if LibRawBigEndian
  199 |     const unsigned char *input0 = input;
  200 |     const unsigned char *input1 = input + rowIncrement;
  201 |     const unsigned char *input2 = input + rowIncrement * 2;
  202 |     const unsigned char *input3 = input + rowIncrement * 3;
  203 | #else
  204 |     const unsigned char *input3 = input;
  205 |     const unsigned char *input2 = input + rowIncrement;
  206 |     const unsigned char *input1 = input + rowIncrement * 2;
  207 |     const unsigned char *input0 = input + rowIncrement * 3;
  208 | #endif
  209 |     for (int col = 0; col < rowIncrement; ++col)
  210 |     {
  211 |       output[0] = input0[col];
  212 |       output[1] = input1[col];
  213 |       output[2] = input2[col];
  214 |       output[3] = input3[col];
  215 |       output += 4;
  216 |     }
  217 |   }
  218 | }
  219 | #endif
  220 |
  221 | static float expandFloats(unsigned char *dst, int tileWidth, int bytesps)
  222 | {
  223 |   float max = 0.f;
  224 |   if (bytesps == 2)
  225 |   {
  226 |     uint16_t *dst16 = (ushort *)dst;
  227 |     uint32_t *dst32 = (unsigned int *)dst;
  228 |     float *f32 = (float *)dst;
  229 |     for (int index = tileWidth - 1; index >= 0; --index)
  230 |     {
  231 |       dst32[index] = __DNG_HalfToFloat(dst16[index]);
  232 |       max = MAX(max, f32[index]);
  233 |     }
  234 |   }
  235 |   else if (bytesps == 3)
  236 |   {
  237 |     uint8_t *dst8 = ((unsigned char *)dst) + (tileWidth - 1) * 3;
  238 |     uint32_t *dst32 = (unsigned int *)dst;
  239 |     float *f32 = (float *)dst;
  240 |     for (int index = tileWidth - 1; index >= 0; --index, dst8 -= 3)
  241 |     {
  242 |       dst32[index] = __DNG_FP24ToFloat(dst8);
  243 |       max = MAX(max, f32[index]);
  244 |     }
  245 |   }
  246 |   else if (bytesps == 4)
  247 |   {
  248 |     float *f32 = (float *)dst;
  249 |     for (int index = 0; index < tileWidth; index++)
  250 |       max = MAX(max, f32[index]);
  251 |   }
  252 |   return max;
  253 | }
  254 |
  255 | struct tile_stripe_data_t
  256 | {
  257 |     bool tiled, striped;
  258 |     int tileCnt;
  259 |     unsigned tileWidth, tileHeight, tilesH, tilesV;
  260 |     INT64 maxBytesInTile;
  261 |     std::vector<INT64> tOffsets, tBytes;
  262 |     tile_stripe_data_t() : tiled(false), striped(false),tileCnt(0),
  263 |         tileWidth(0),tileHeight(0),tilesH(0),tilesV(0),
  264 |         maxBytesInTile(0){}
  265 |     void init(tiff_ifd_t *ifd, const libraw_image_sizes_t&, const unpacker_data_t&,
  266 |         short _order,
  267 |         LibRaw_abstract_datastream *stream);
  268 | };
  269 |
  270 | static unsigned static_get4(LibRaw_abstract_datastream *stream, short _order)
  271 | {
  272 |     uchar str[4] = { 0xff, 0xff, 0xff, 0xff };
  273 |     stream->read(str, 1, 4);
  274 |     return libraw_sget4_static(_order, str);
  275 | }
  276 |
  277 |
  278 | void tile_stripe_data_t::init(tiff_ifd_t *ifd, const libraw_image_sizes_t& sizes,
  279 |     const unpacker_data_t& unpacker_data, short _order, LibRaw_abstract_datastream *stream)
  280 | {
  281 |     tiled = (unpacker_data.tile_width <= sizes.raw_width) && (unpacker_data.tile_length <= sizes.raw_height);
  282 |     striped = (ifd->rows_per_strip > 0 && ifd->rows_per_strip < sizes.raw_height) && ifd->strip_byte_counts_count > 0;
  283 |
  284 |     tileWidth = tiled ? unpacker_data.tile_width : sizes.raw_width;
  285 |     tileHeight = tiled ? unpacker_data.tile_length :(striped ? ifd->rows_per_strip : sizes.raw_height);
  286 |     tilesH = tiled ? (sizes.raw_width + tileWidth - 1) / tileWidth : 1;
  287 |     tilesV = tiled ? (sizes.raw_height + tileHeight - 1) / tileHeight :
  288 |         (striped ? ((sizes.raw_height + ifd->rows_per_strip - 1) / ifd->rows_per_strip) : 1);
  289 |     tileCnt = tilesH * tilesV;
  290 |
  291 |     if (tileCnt < 1 || tileCnt > 1000000)
  292 |         throw LIBRAW_EXCEPTION_DECODE_RAW;
  293 |
> 294 |     tOffsets = std::vector<INT64>(tileCnt,0);
  295 |     tBytes = std::vector <INT64>(tileCnt,0);
  296 |
  297 |     if (tiled)
  298 |         for (int t = 0; t < tileCnt; ++t)
  299 |             tOffsets[t] = static_get4(stream, _order);
  300 |     else if (striped)
  301 |         for (int t = 0; t < tileCnt && t < ifd->strip_offsets_count; ++t)
  302 |             tOffsets[t] = ifd->strip_offsets[t];
  303 |     else
  304 |         tOffsets[0] = ifd->offset;
  305 |
  306 |     maxBytesInTile = 0;
  307 |
  308 |     if (tileCnt == 1 || (!tiled && !striped))
  309 |         tBytes[0] = maxBytesInTile = ifd->bytes;
  310 |     else if (tiled)
  311 |     {
  312 |         // ifd->bytes points to tile size table if more than 1 tile exists
  313 |         stream->seek(ifd->bytes, SEEK_SET);
  314 |         for (int t = 0; t < tileCnt; ++t)
  315 |         {
  316 |             tBytes[t] = static_get4(stream, _order); ;
  317 |             maxBytesInTile = MAX(maxBytesInTile, tBytes[t]);
  318 |         }
  319 |     }
  320 |     else if (striped)
  321 |         for (int t = 0; t < tileCnt && t < ifd->strip_byte_counts_count; ++t)
  322 |         {
  323 |             tBytes[t] = ifd->strip_byte_counts[t];
  324 |             maxBytesInTile = MAX(maxBytesInTile, tBytes[t]);
  325 |         }
  326 | }
  327 |
  328 | #ifdef USE_ZLIB
  329 | void LibRaw::deflate_dng_load_raw()
  330 | {
  331 |   int iifd = find_ifd_by_offset(libraw_internal_data.unpacker_data.data_offset);
  332 |   if(iifd < 0 || iifd > (int)libraw_internal_data.identify_data.tiff_nifds)
  333 |       throw LIBRAW_EXCEPTION_DECODE_RAW;
  334 |   struct tiff_ifd_t *ifd = &tiff_ifd[iifd];
  335 |
  336 |   float *float_raw_image = 0;
  337 |   float max = 0.f;
  338 |
  339 |   if (ifd->samples != 1 && ifd->samples != 3 && ifd->samples != 4)
  340 |     throw LIBRAW_EXCEPTION_DECODE_RAW;
  341 |
  342 |   if (libraw_internal_data.unpacker_data.tiff_samples != (unsigned)ifd->samples)
  343 |     throw LIBRAW_EXCEPTION_DECODE_RAW; // Wrong IFD
  344 |
  345 |   if (imgdata.idata.filters && ifd->samples > 1)
  346 |     throw LIBRAW_EXCEPTION_DECODE_RAW;
  347 |
  348 |   tile_stripe_data_t tiles;
  349 |   tiles.init(ifd, imgdata.sizes, libraw_internal_data.unpacker_data, libraw_internal_data.unpacker_data.order,
  350 |       libraw_internal_data.internal_data.input);
  351 |
  352 |   if (tiles.tBytes.size() < 1)
  353 | 	  throw LIBRAW_EXCEPTION_IO_CORRUPT;
  354 |
  355 |   // Ensure less then 2GB per compressed tile
  356 |   INT64 maxcomprlen = tiles.tBytes[0];
  357 |   for (int i = 1; i < tiles.tBytes.size(); i++)
  358 | 	  maxcomprlen = MAX(maxcomprlen, tiles.tBytes[i]);
  359 |
  360 |   if(maxcomprlen >= (1LL << 31) || maxcomprlen < 0)
  361 | 	  throw LIBRAW_EXCEPTION_TOOBIG;
  362 |
  363 |   // Max bytes: 2^16 raw width * 2^2 bytes/pixel * 2^2 channels = 2^20, so check against 2^22
  364 |   INT64 rowbytes = INT64(MAX(tiles.tileWidth, imgdata.sizes.raw_width)) * 4ULL * INT64(ifd->samples);
  365 |   if (rowbytes > (1LL << 22))
  366 |     throw LIBRAW_EXCEPTION_TOOBIG;
  367 |
  368 |   if (ifd->sample_format == 3)
  369 |   {
  370 |     INT64 raw_bytes = INT64(tiles.tileCnt) * INT64(tiles.tileWidth) * INT64(tiles.tileHeight) * INT64(ifd->samples) * sizeof(float);
  371 |     if (raw_bytes > INT64(imgdata.rawparams.max_raw_memory_mb) * INT64(1024 * 1024))
  372 |       throw LIBRAW_EXCEPTION_TOOBIG;
  373 |     float_raw_image = (float *)calloc(raw_bytes, 1);
  374 |   }
  375 |   else
  376 |     throw LIBRAW_EXCEPTION_DECODE_RAW; // Only float deflated supported
  377 |
  378 |   int xFactor;
  379 |   switch (ifd->predictor)
  380 |   {
  381 |   case 3:
  382 |   default:
  383 |     xFactor = 1;
  384 |     break;
  385 |   case 34894:
  386 |     xFactor = 2;
  387 |     break;
  388 |   case 34895:
  389 |     xFactor = 4;
  390 |     break;
  391 |   }
  392 |
  393 |   INT64 tilePixels =  INT64(tiles.tileWidth) * INT64(tiles.tileHeight);
  394 |   unsigned pixelSize = sizeof(float) * ifd->samples;

Reach line at /src/libraw/src/decoders/fp_dng.cpp:294 (observed count 754).


   98 |     }
   99 |     else
  100 |     {
  101 |       move_row = _move[i].row;
  102 |       move_col = _move[i].col;
  103 |     }
  104 |     for (; tidx < 16; tidx++)
  105 |       if (tiff_ifd[tidx].t_width == imgdata.sizes.raw_width &&
  106 |           tiff_ifd[tidx].t_height == imgdata.sizes.raw_height &&
  107 |           tiff_ifd[tidx].bps > 8 && tiff_ifd[tidx].samples == 1)
  108 |         break;
  109 |     if (tidx >= 16)
  110 |       break;
  111 |     imgdata.rawdata.raw_image = plane;
  112 |     ID.input->seek(tiff_ifd[tidx].offset, SEEK_SET);
  113 |     imgdata.idata.filters = 0xb4b4b4b4;
  114 |     libraw_internal_data.unpacker_data.data_offset = tiff_ifd[tidx].offset;
  115 |     (this->*pentax_component_load_raw)();
  116 |     for (int row = 0; row < imgdata.sizes.raw_height - move_row; row++)
  117 |     {
  118 |       int colors[2];
  119 |       for (int c = 0; c < 2; c++)
  120 |         colors[c] = COLOR(row, c);
  121 |       ushort *srcrow = &plane[imgdata.sizes.raw_width * row];
  122 |       ushort(*dstrow)[4] =
  123 |           &result[(imgdata.sizes.raw_width) * (row + move_row) + move_col];
  124 |       for (int col = 0; col < imgdata.sizes.raw_width - move_col; col++)
  125 |         dstrow[col][colors[col % 2]] = srcrow[col];
  126 |     }
  127 |     tidx++;
  128 |   }
  129 |
  130 |   if (imgdata.color.cblack[4] == 2 && imgdata.color.cblack[5] == 2)
  131 |     for (int c = 0; c < 4; c++)
  132 |       imgdata.color.cblack[FC(c / 2, c % 2)] +=
  133 |           imgdata.color.cblack[6 +
  134 |                                c / 2 % imgdata.color.cblack[4] *
  135 |                                    imgdata.color.cblack[5] +
  136 |                                c % 2 % imgdata.color.cblack[5]];
  137 |   imgdata.color.cblack[4] = imgdata.color.cblack[5] = 0;
  138 |
  139 |   // assign things back:
  140 |   imgdata.sizes.raw_pitch = imgdata.sizes.raw_width * 8;
  141 |   imgdata.idata.filters = 0;
  142 |   imgdata.rawdata.raw_alloc = imgdata.rawdata.color4_image = result;
  143 |   free(plane);
  144 |   imgdata.rawdata.raw_image = 0;
  145 | }
  146 |
  147 | void LibRaw::hasselblad_full_load_raw()
  148 | {
  149 |   int row, col;
  150 |
  151 |   for (row = 0; row < S.height; row++)
  152 |     for (col = 0; col < S.width; col++)
  153 |     {
  154 |       read_shorts(&imgdata.image[row * S.width + col][2], 1); // B
  155 |       read_shorts(&imgdata.image[row * S.width + col][1], 1); // G
  156 |       read_shorts(&imgdata.image[row * S.width + col][0], 1); // R
  157 |     }
  158 | }
  159 |
  160 | static inline void unpack7bytesto4x16(unsigned char *src, unsigned short *dest)
  161 | {
  162 |   dest[0] = (src[0] << 6) | (src[1] >> 2);
  163 |   dest[1] = ((src[1] & 0x3) << 12) | (src[2] << 4) | (src[3] >> 4);
  164 |   dest[2] = (src[3] & 0xf) << 10 | (src[4] << 2) | (src[5] >> 6);
  165 |   dest[3] = ((src[5] & 0x3f) << 8) | src[6];
  166 | }
  167 |
  168 | static inline void unpack28bytesto16x16ns(unsigned char *src,
  169 |                                           unsigned short *dest)
  170 | {
  171 |   dest[0] = (src[3] << 6) | (src[2] >> 2);
  172 |   dest[1] = ((src[2] & 0x3) << 12) | (src[1] << 4) | (src[0] >> 4);
  173 |   dest[2] = (src[0] & 0xf) << 10 | (src[7] << 2) | (src[6] >> 6);
  174 |   dest[3] = ((src[6] & 0x3f) << 8) | src[5];
  175 |   dest[4] = (src[4] << 6) | (src[11] >> 2);
  176 |   dest[5] = ((src[11] & 0x3) << 12) | (src[10] << 4) | (src[9] >> 4);
  177 |   dest[6] = (src[9] & 0xf) << 10 | (src[8] << 2) | (src[15] >> 6);
  178 |   dest[7] = ((src[15] & 0x3f) << 8) | src[14];
  179 |   dest[8] = (src[13] << 6) | (src[12] >> 2);
  180 |   dest[9] = ((src[12] & 0x3) << 12) | (src[19] << 4) | (src[18] >> 4);
  181 |   dest[10] = (src[18] & 0xf) << 10 | (src[17] << 2) | (src[16] >> 6);
  182 |   dest[11] = ((src[16] & 0x3f) << 8) | src[23];
  183 |   dest[12] = (src[22] << 6) | (src[21] >> 2);
  184 |   dest[13] = ((src[21] & 0x3) << 12) | (src[20] << 4) | (src[27] >> 4);
  185 |   dest[14] = (src[27] & 0xf) << 10 | (src[26] << 2) | (src[25] >> 6);
  186 |   dest[15] = ((src[25] & 0x3f) << 8) | src[24];
  187 | }
  188 |
  189 | #define swab32(x)                                                              \
  190 |   ((unsigned int)((((unsigned int)(x) & (unsigned int)0x000000ffUL) << 24) |   \
  191 |                   (((unsigned int)(x) & (unsigned int)0x0000ff00UL) << 8) |    \
  192 |                   (((unsigned int)(x) & (unsigned int)0x00ff0000UL) >> 8) |    \
  193 |                   (((unsigned int)(x) & (unsigned int)0xff000000UL) >> 24)))
  194 |
  195 | static inline void swab32arr(unsigned *arr, unsigned len)
  196 | {
  197 |   for (unsigned i = 0; i < len; i++)
> 198 |     arr[i] = swab32(arr[i]);
  199 | }
  200 | #undef swab32
  201 |
  202 | static inline void unpack7bytesto4x16_nikon(unsigned char *src,
  203 |                                             unsigned short *dest)
  204 | {
  205 |   dest[3] = (src[6] << 6) | (src[5] >> 2);
  206 |   dest[2] = ((src[5] & 0x3) << 12) | (src[4] << 4) | (src[3] >> 4);
  207 |   dest[1] = (src[3] & 0xf) << 10 | (src[2] << 2) | (src[1] >> 6);
  208 |   dest[0] = ((src[1] & 0x3f) << 8) | src[0];
  209 | }
  210 |
  211 | static inline void unpack21bytesto12x16_nikon(unsigned char *src, unsigned short (*dest)[4])
  212 | {
  213 | 	// bytes 0-6
  214 |   dest[0][0] = ((src[1] & 0x3f) << 8) | src[0];
  215 |   dest[0][1] = (src[3] & 0xf) << 10 | (src[2] << 2) | (src[1] >> 6);
  216 |   dest[0][2] = ((src[5] & 0x3) << 12) | (src[4] << 4) | (src[3] >> 4);
  217 |   dest[1][0] = (src[6] << 6) | (src[5] >> 2);
  218 |   // bytes 7-13
  219 |   dest[1][1] = ((src[8] & 0x3f) << 8) | src[7];
  220 |   dest[1][2] = (src[10] & 0xf) << 10 | (src[9] << 2) | (src[8] >> 6);
  221 |   dest[2][0] = ((src[12] & 0x3) << 12) | (src[11] << 4) | (src[10] >> 4);
  222 |   dest[2][1] = (src[13] << 6) | (src[12] >> 2);
  223 |   // bytes 14-20
  224 |   dest[2][2] = ((src[15] & 0x3f) << 8) | src[14];
  225 |   dest[3][0] = (src[17] & 0xf) << 10 | (src[16] << 2) | (src[15] >> 6);
  226 |   dest[3][1] = ((src[19] & 0x3) << 12) | (src[18] << 4) | (src[17] >> 4);
  227 |   dest[3][2] = (src[20] << 6) | (src[19] >> 2);
  228 | }
  229 |
  230 |
  231 | void LibRaw::nikon_14bit_load_raw()
  232 | {
  233 |   int cps = (imgdata.idata.filters == 0 && imgdata.idata.colors == 3) ? 3 : 1;
  234 |
  235 |   if (cps == 1 && !imgdata.rawdata.raw_image)
  236 | 	  throw LIBRAW_EXCEPTION_DECODE_RAW;
  237 |   if(cps == 3 && !imgdata.image)
  238 |     throw LIBRAW_EXCEPTION_DECODE_RAW;
  239 |
  240 |   const unsigned linelen =
  241 |       (unsigned)(ceilf((float)(S.raw_width * cps * 7 / 4) / 16.0f)) *
  242 |       16; // 14512; // S.raw_width * 7 / 4;
  243 |   const unsigned pitch = S.raw_pitch ? S.raw_pitch /( (cps>=3)? 8 : 2) : S.raw_width;
  244 |   unsigned char *buf = (unsigned char *)calloc(linelen,1);
  245 |   for (int row = 0; row < S.raw_height; row++)
  246 |   {
  247 |     unsigned bytesread =
  248 |         libraw_internal_data.internal_data.input->read(buf, 1, linelen);
  249 | 	if (cps == 1)
  250 | 	{
  251 | 		unsigned short *dest = &imgdata.rawdata.raw_image[pitch * row];
  252 | 		// swab32arr((unsigned *)buf, bytesread / 4);
  253 | 		for (unsigned int sp = 0, dp = 0;
  254 | 			dp < pitch - 3 && sp < linelen - 6 && sp < bytesread - 6;
  255 | 			sp += 7, dp += 4)
  256 | 			unpack7bytesto4x16_nikon(buf + sp, dest + dp);
  257 | 	}
  258 | 	else if (cps == 3)
  259 | 	{
  260 |       unsigned short (*dest)[4] = &imgdata.image[pitch * row];
  261 |       // swab32arr((unsigned *)buf, bytesread / 4);
  262 |       for (unsigned int sp = 0, dp = 0;
  263 | 		  dp < pitch - 3 && sp < linelen - 20 && sp < bytesread - 20;
  264 | 		  sp += 21, dp += 4)
  265 |         unpack21bytesto12x16_nikon(buf + sp, dest + dp);
  266 | 	}
  267 |   }
  268 |   free(buf);
  269 | }
  270 |
  271 | void LibRaw::fuji_14bit_load_raw()
  272 | {
  273 |   const unsigned linelen = S.raw_width * 7 / 4;
  274 |   const unsigned pitch = S.raw_pitch ? S.raw_pitch / 2 : S.raw_width;
  275 |   unsigned char *buf = (unsigned char *)calloc(linelen,1);
  276 |
  277 |   for (int row = 0; row < S.raw_height; row++)
  278 |   {
  279 |     unsigned bytesread =
  280 |         libraw_internal_data.internal_data.input->read(buf, 1, linelen);
  281 |     unsigned short *dest = &imgdata.rawdata.raw_image[pitch * row];
  282 |     if (bytesread % 28)
  283 |     {
  284 |       swab32arr((unsigned *)buf, bytesread / 4);
  285 |       for (unsigned int sp = 0, dp = 0;
  286 |            dp < pitch - 3 && sp < linelen - 6 && sp < bytesread - 6;
  287 |            sp += 7, dp += 4)
  288 |         unpack7bytesto4x16(buf + sp, dest + dp);
  289 |     }
  290 |     else
  291 |       for (unsigned int sp = 0, dp = 0;
  292 |            dp < pitch - 15 && sp < linelen - 27 && sp < bytesread - 27;
  293 |            sp += 28, dp += 16)
  294 |         unpack28bytesto16x16ns(buf + sp, dest + dp);
  295 |   }
  296 |   free(buf);
  297 | }
  298 | void LibRaw::nikon_load_padded_packed_raw() // 12 bit per pixel, padded to 16

Reach line at /src/libraw/src/decoders/decoders_libraw.cpp:198 (observed count 10700).


  640 |   int *offset, len[2], pred[2], row, col, i, j;
  641 |   ushort *pixel;
  642 |   short(*c_black)[2], (*r_black)[2];
  643 |   if (ph1.format == 6)
  644 |     throw LIBRAW_EXCEPTION_IO_CORRUPT;
  645 |
  646 |   pixel = (ushort *)calloc(raw_width * 3 + raw_height * 4, 2);
  647 |   offset = (int *)(pixel + raw_width);
  648 |   fseek(ifp, strip_offset, SEEK_SET);
  649 |   for (row = 0; row < raw_height; row++)
  650 |     offset[row] = get4();
  651 |   c_black = (short(*)[2])(offset + raw_height);
  652 |   fseek(ifp, ph1.black_col, SEEK_SET);
  653 |   if (ph1.black_col)
  654 |     read_shorts((ushort *)c_black[0], raw_height * 2);
  655 |   r_black = c_black + raw_height;
  656 |   fseek(ifp, ph1.black_row, SEEK_SET);
  657 |   if (ph1.black_row)
  658 |     read_shorts((ushort *)r_black[0], raw_width * 2);
  659 |
  660 |   // Copy data to internal copy (ever if not read)
  661 |   if (ph1.black_col || ph1.black_row)
  662 |   {
  663 |     imgdata.rawdata.ph1_cblack =
  664 |         (short(*)[2])calloc(raw_height * 2, sizeof(ushort));
  665 |     memmove(imgdata.rawdata.ph1_cblack, (ushort *)c_black[0],
  666 |             raw_height * 2 * sizeof(ushort));
  667 |     imgdata.rawdata.ph1_rblack =
  668 |         (short(*)[2])calloc(raw_width * 2, sizeof(ushort));
  669 |     memmove(imgdata.rawdata.ph1_rblack, (ushort *)r_black[0],
  670 |             raw_width * 2 * sizeof(ushort));
  671 |   }
  672 |
  673 |   for (i = 0; i < 256; i++)
  674 |     curve[i] = ushort(float(i * i) / 3.969f + 0.5f);
  675 |   try
  676 |   {
  677 |     for (row = 0; row < raw_height; row++)
  678 |     {
  679 |       checkCancel();
  680 |       fseek(ifp, data_offset + offset[row], SEEK_SET);
  681 |       ph1_bits(-1);
  682 |       pred[0] = pred[1] = 0;
  683 |       for (col = 0; col < raw_width; col++)
  684 |       {
  685 |         if (col >= (raw_width & -8))
  686 |           len[0] = len[1] = 14;
  687 |         else if ((col & 7) == 0)
  688 |           for (i = 0; i < 2; i++)
  689 |           {
  690 |             for (j = 0; j < 5 && !ph1_bits(1); j++)
  691 |               ;
  692 |             if (j--)
  693 |               len[i] = length[j * 2 + ph1_bits(1)];
  694 |           }
  695 |         if ((i = len[col & 1]) == 14)
  696 |           pixel[col] = pred[col & 1] = ph1_bits(16);
  697 |         else
  698 |           pixel[col] = pred[col & 1] += ph1_bits(i) + 1 - (1 << (i - 1));
  699 |         if (pred[col & 1] >> 16)
  700 |           derror();
  701 |         if (ph1.format == 5 && pixel[col] < 256)
  702 |           pixel[col] = curve[pixel[col]];
  703 |       }
  704 |       if (ph1.format == 8)
  705 |         memmove(&RAW(row, 0), &pixel[0], raw_width * 2);
  706 |       else
  707 |         for (col = 0; col < raw_width; col++)
  708 |           RAW(row, col) = pixel[col] << 2;
  709 |     }
  710 |   }
  711 |   catch (...)
  712 |   {
  713 |     free(pixel);
  714 |     throw;
  715 |   }
  716 |   free(pixel);
  717 |   maximum = 0xfffc - ph1.t_black;
  718 | }
  719 |
  720 | void LibRaw::hasselblad_load_raw()
  721 | {
  722 |   struct jhead jh;
  723 |   int shot, row, col, *back[5]={0,0,0,0,0},
  724 |  	 len[2], diff[12], pred, sh, f, c;
  725 |   unsigned s;
  726 |   unsigned upix, urow, ucol;
  727 |   ushort *ip;
  728 |
  729 |   if (!ljpeg_start(&jh, 0))
  730 |     return;
  731 |   order = 0x4949;
  732 |   ph1_bits(-1);
  733 |   try
  734 |   {
  735 |     back[4] = (int *)calloc(raw_width, 3 * sizeof **back);
  736 |     FORC3 back[c] = back[4] + c * raw_width;
  737 |     cblack[6] >>= sh = tiff_samples > 1;
  738 |     shot = LIM(shot_select, 1, tiff_samples) - 1;
  739 |     for (row = 0; row < raw_height; row++)
> 740 |     {
  741 |       checkCancel();
  742 |       FORC4 back[(c + 3) & 3] = back[c];
  743 |       for (col = 0; col < raw_width; col += 2)
  744 |       {
  745 |         for (s = 0; s < tiff_samples * 2; s += 2)
  746 |         {
  747 |           FORC(2) len[c] = ph1_huff(jh.huff[0]);
  748 |           FORC(2)
  749 |           {
  750 |             diff[s + c] = ph1_bits(len[c]);
  751 |             if (len[c] > 0 && (diff[s + c] & (1 << (len[c] - 1))) == 0)
  752 |               diff[s + c] -= (1 << len[c]) - 1;
  753 |             if (diff[s + c] == 65535)
  754 |               diff[s + c] = -32768;
  755 |           }
  756 |         }
  757 |         for (s = col; s < unsigned(col + 2); s++)
  758 |         {
  759 |           pred = 0x8000 + load_flags;
  760 |           if (col)
  761 |             pred = back[2][s - 2];
  762 |           if (col && row > 1)
  763 |             switch (jh.psv)
  764 |             {
  765 |             case 11:
  766 |               pred += back[0][s] / 2 - back[0][s - 2] / 2;
  767 |               break;
  768 |             }
  769 |           f = (row & 1) * 3 ^ ((col + s) & 1);
  770 |           FORC(int(tiff_samples))
  771 |           {
  772 |             pred += diff[(s & 1) * tiff_samples + c];
  773 |             upix = pred >> sh & 0xffff;
  774 |             if (raw_image && c == shot)
  775 |               RAW(row, s) = upix;
  776 |             if (image)
  777 |             {
  778 |               urow = row - top_margin + (c & 1);
  779 |               ucol = col - left_margin - ((c >> 1) & 1);
  780 |               ip = &image[urow * width + ucol][f];
  781 |               if (urow < height && ucol < width)
  782 |                 *ip = c < 4 ? upix : (*ip + upix) >> 1;
  783 |             }
  784 |           }
  785 |           back[2][s] = pred;
  786 |         }
  787 |       }
  788 |     }
  789 |   }
  790 |   catch (...)
  791 |   {
  792 |     if(back[4])
  793 |     	free(back[4]);
  794 |     ljpeg_end(&jh);
  795 |     throw;
  796 |   }
  797 |   if(back[4])
  798 |     free(back[4]);
  799 |   ljpeg_end(&jh);
  800 |   if (image)
  801 |     mix_green = 1;
  802 | }
  803 |
  804 | void LibRaw::leaf_hdr_load_raw()
  805 | {
  806 |   ushort *pixel = 0;
  807 |   unsigned tile = 0, r, c, row, col;
  808 |
  809 |   if (!filters || !raw_image)
  810 |   {
  811 |     if (!image)
  812 |       throw LIBRAW_EXCEPTION_IO_CORRUPT;
  813 |     pixel = (ushort *)calloc(raw_width, sizeof *pixel);
  814 |   }
  815 |   try
  816 |   {
  817 |     FORC(tiff_samples)
  818 |     for (r = 0; r < raw_height; r++)
  819 |     {
  820 |       checkCancel();
  821 |       if (r % tile_length == 0)
  822 |       {
  823 |         fseek(ifp, data_offset + 4 * tile++, SEEK_SET);
  824 |         fseek(ifp, get4(), SEEK_SET);
  825 |       }
  826 |       if (filters && c != shot_select)
  827 |         continue;
  828 |       if (filters && raw_image)
  829 |         pixel = raw_image + r * raw_width;
  830 |       read_shorts(pixel, raw_width);
  831 |       if (!filters && image && (row = r - top_margin) < height)
  832 |         for (col = 0; col < width && col + left_margin < raw_width; col++)
  833 |           image[row * width + col][c] = pixel[col + left_margin];
  834 |     }
  835 |   }
  836 |   catch (...)
  837 |   {
  838 |     if (!filters)
  839 |       free(pixel);
  840 |     throw;

Reach line at /src/libraw/src/decoders/load_mfbacks.cpp:740 (observed count 439000).


  3187 |       if (ival == 15     // V2000
  3188 |           || ival == -1  // v3000
  3189 |       ) {
  3190 |         atom->setNumExplicitHs(0);
  3191 |       } else {
  3192 |         if (static_cast<int>(atom->getValence(Atom::ValenceType::EXPLICIT)) >
  3193 |             ival) {
  3194 |           BOOST_LOG(rdWarningLog)
  3195 |               << "atom " << atom->getIdx() << " has specified valence (" << ival
  3196 |               << ") smaller than the drawn valence "
  3197 |               << atom->getValence(Atom::ValenceType::EXPLICIT) << "."
  3198 |               << std::endl;
  3199 |           atom->setNumExplicitHs(0);
  3200 |         } else {
  3201 |           atom->setNumExplicitHs(ival -
  3202 |                                  atom->getValence(Atom::ValenceType::EXPLICIT));
  3203 |         }
  3204 |       }
  3205 |     }
  3206 |     atom->clearProp(common_properties::molTotValence);
  3207 |   }
  3208 |   processSGroups(mol);
  3209 | }
  3210 |
  3211 | }  // namespace
  3212 | namespace FileParserUtils {
  3213 | bool ParseV3000CTAB(std::istream *inStream, unsigned int &line, RWMol *mol,
  3214 |                     Conformer *&conf, bool &chiralityPossible,
  3215 |                     unsigned int &nAtoms, unsigned int &nBonds,
  3216 |                     bool strictParsing, bool expectMEND,
  3217 |                     bool expectMacroAtoms) {
  3218 |   PRECONDITION(inStream, "bad stream");
  3219 |   PRECONDITION(mol, "bad molecule");
  3220 |
  3221 |   std::string tempStr;
  3222 |   std::vector<std::string> splitLine;
  3223 |
  3224 |   bool fileComplete = false;
  3225 |
  3226 |   tempStr = getV3000Line(inStream, line);
  3227 |   boost::to_upper(tempStr);
  3228 |   if (tempStr.length() < 10 || tempStr.substr(0, 10) != "BEGIN CTAB") {
  3229 |     std::ostringstream errout;
  3230 |     errout << "BEGIN CTAB line not found on line " << line;
  3231 |     throw FileParseException(errout.str());
  3232 |   }
  3233 |
  3234 |   tempStr = getV3000Line(inStream, line);
  3235 |   boost::to_upper(tempStr);
  3236 |   if (tempStr.size() < 8 || tempStr.substr(0, 7) != "COUNTS ") {
  3237 |     std::ostringstream errout;
  3238 |     errout << "Bad counts line : '" << tempStr << "' on line " << line;
  3239 |     throw FileParseException(errout.str());
  3240 |   }
  3241 |   std::string trimmed =
  3242 |       boost::trim_copy(tempStr.substr(7, tempStr.length() - 7));
  3243 |   boost::split(splitLine, trimmed, boost::is_any_of(" \t"),
  3244 |                boost::token_compress_on);
  3245 |   if (splitLine.size() < 2) {
  3246 |     std::ostringstream errout;
  3247 |     errout << "Bad counts line : '" << tempStr << "' on line " << line;
  3248 |     throw FileParseException(errout.str());
  3249 |   }
  3250 |
  3251 |   nAtoms = FileParserUtils::toUnsigned(splitLine[0]);
  3252 |   nBonds = FileParserUtils::toUnsigned(splitLine[1]);
  3253 |   conf = new Conformer(nAtoms);
  3254 |
  3255 |   unsigned int nSgroups = 0, n3DConstraints = 0, chiralFlag = 0;
  3256 |
  3257 |   if (splitLine.size() > 2) {
  3258 |     nSgroups = FileParserUtils::toUnsigned(splitLine[2]);
  3259 |   }
  3260 |   if (splitLine.size() > 3) {
  3261 |     n3DConstraints = FileParserUtils::toUnsigned(splitLine[3]);
  3262 |   }
  3263 |   if (splitLine.size() > 4) {
  3264 |     chiralFlag = FileParserUtils::toUnsigned(splitLine[4]);
  3265 |   }
  3266 |
  3267 |   mol->setProp(common_properties::_MolFileChiralFlag, chiralFlag);
  3268 |
  3269 |   if (nAtoms) {
  3270 |     ParseV3000AtomBlock(inStream, line, nAtoms, mol, conf, strictParsing,
  3271 |                         expectMacroAtoms);
  3272 |   }
  3273 |   if (nBonds) {
  3274 |     ParseV3000BondBlock(inStream, line, nBonds, mol, chiralityPossible);
  3275 |   }
  3276 |
  3277 |   tempStr = getV3000Line(inStream, line);
  3278 |   // do link nodes:
  3279 |   boost::to_upper(tempStr);
  3280 |   while (tempStr.length() > 8 && tempStr.substr(0, 8) == "LINKNODE") {
  3281 |     boost::to_upper(tempStr);
  3282 |     // if the line has nothing on it we just ignore it
  3283 |     if (tempStr.size() > 9) {
  3284 |       std::string existing = "";
  3285 |       if (mol->getPropIfPresent(common_properties::molFileLinkNodes,
  3286 |                                 existing)) {
> 3287 |         existing += "|";
  3288 |       }
  3289 |       existing += tempStr.substr(9);  // skip the "LINKNODE "
  3290 |       mol->setProp(common_properties::molFileLinkNodes, existing);
  3291 |     }
  3292 |     tempStr = getV3000Line(inStream, line);
  3293 |   }
  3294 |
  3295 |   bool sgroupFound = false;
  3296 |   bool obj3dFound = false;
  3297 |   boost::to_upper(tempStr);
  3298 |   while (tempStr.length() > 5 && tempStr.substr(0, 5) == "BEGIN") {
  3299 |     if (tempStr.length() >= 12 && tempStr.substr(0, 12) == "BEGIN SGROUP") {
  3300 |       if (sgroupFound) {
  3301 |         std::ostringstream errout;
  3302 |         errout << "BEGIN SGROUP found more than once on line " << line;
  3303 |         throw FileParseException(errout.str());
  3304 |
  3305 |       } else if (!nSgroups) {
  3306 |         std::ostringstream errout;
  3307 |         errout << "BEGIN SGROUP  found but Sgroups NOT expected on line "
  3308 |                << line;
  3309 |         if (strictParsing) {
  3310 |           throw FileParseException(errout.str());
  3311 |         } else {
  3312 |           BOOST_LOG(rdWarningLog) << errout.str() << std::endl;
  3313 |           // Prepare to read a lot of sgroups
  3314 |           nSgroups = std::numeric_limits<unsigned int>::max();
  3315 |         }
  3316 |       }
  3317 |       sgroupFound = true;
  3318 |       tempStr =
  3319 |           ParseV3000SGroupsBlock(inStream, line, nSgroups, mol, strictParsing);
  3320 |       boost::to_upper(tempStr);
  3321 |       if (tempStr.length() < 10 || tempStr.substr(0, 10) != "END SGROUP") {
  3322 |         std::ostringstream errout;
  3323 |         errout << "END SGROUP line not found on line " << line;
  3324 |         if (strictParsing) {
  3325 |           throw FileParseException(errout.str());
  3326 |         } else {
  3327 |           BOOST_LOG(rdWarningLog) << errout.str() << std::endl;
  3328 |         }
  3329 |       } else {
  3330 |         tempStr = getV3000Line(inStream, line);
  3331 |         boost::to_upper(tempStr);
  3332 |       }
  3333 |
  3334 |     } else if (tempStr.length() >= 15 &&
  3335 |                tempStr.substr(6, 10) == "COLLECTION") {
  3336 |       tempStr = parseEnhancedStereo(inStream, line, mol, strictParsing);
  3337 |       boost::to_upper(tempStr);
  3338 |     } else if (tempStr.length() >= 11 &&
  3339 |                tempStr.substr(0, 11) == "BEGIN OBJ3D") {
  3340 |       if (obj3dFound) {
  3341 |         std::ostringstream errout;
  3342 |         errout << "BEGIN OBJ3D found more than once on line " << line;
  3343 |         throw FileParseException(errout.str());
  3344 |       }
  3345 |       if (!n3DConstraints) {
  3346 |         std::ostringstream errout;
  3347 |         errout << "BEGIN OBJ3D found but 3n3DConstraints NOT expected on line "
  3348 |                << line;
  3349 |         if (strictParsing) {
  3350 |           throw FileParseException(errout.str());
  3351 |         } else {
  3352 |           BOOST_LOG(rdWarningLog) << errout.str() << std::endl;
  3353 |         }
  3354 |       }
  3355 |       BOOST_LOG(rdWarningLog)
  3356 |           << "3D constraint information in mol block ignored at line " << line
  3357 |           << std::endl;
  3358 |       obj3dFound = true;
  3359 |       for (unsigned int i = 0; i < n3DConstraints; ++i) {
  3360 |         tempStr = getV3000Line(inStream, line);
  3361 |       }
  3362 |       tempStr = getV3000Line(inStream, line);
  3363 |       boost::to_upper(tempStr);
  3364 |       if (tempStr.length() < 9 || tempStr.substr(0, 9) != "END OBJ3D") {
  3365 |         std::ostringstream errout;
  3366 |         errout << "END OBJ3D line not found on line " << line;
  3367 |         if (strictParsing) {
  3368 |           throw FileParseException(errout.str());
  3369 |         } else {
  3370 |           BOOST_LOG(rdWarningLog) << errout.str() << std::endl;
  3371 |         }
  3372 |       }
  3373 |       tempStr = getV3000Line(inStream, line);
  3374 |       boost::to_upper(tempStr);
  3375 |     } else {
  3376 |       // skip blocks we don't know how to read
  3377 |       BOOST_LOG(rdWarningLog) << "skipping block at line " << line << ": '"
  3378 |                               << tempStr << "'" << std::endl;
  3379 |       while (tempStr.length() < 3 || tempStr.substr(0, 3) != "END") {
  3380 |         tempStr = getV3000Line(inStream, line);
  3381 |       }
  3382 |       tempStr = getV3000Line(inStream, line);
  3383 |       boost::to_upper(tempStr);
  3384 |     }
  3385 |   }
  3386 |
  3387 |   if (nSgroups && !sgroupFound) {

Reach line at /src/rdkit/Code/GraphMol/FileParsers/MolFileParser.cpp:3287 (observed count 1420).


  360 |   unsigned int pos = 6;
  361 |   bool ok;
  362 |   unsigned int nent =
  363 |       ParseSGroupIntField(ok, strictParsing, text, line, pos, true);
  364 |   if (!ok) {
  365 |     return;
  366 |   }
  367 |
  368 |   for (unsigned int ie = 0; ie < nent; ++ie) {
  369 |     if (text.size() < pos + 8) {
  370 |       std::ostringstream errout;
  371 |       errout << "SGroup SLB line too short: '" << text << "' on line " << line;
  372 |       SGroupWarnOrThrow<>(strictParsing, errout.str());
  373 |       return;
  374 |     }
  375 |
  376 |     unsigned int sgIdx =
  377 |         ParseSGroupIntField(ok, strictParsing, text, line, pos);
  378 |     if (!ok) {
  379 |       return;
  380 |     }
  381 |     SubstanceGroup *sgroup = FindSgIdx(sGroupMap, sgIdx, line);
  382 |     if (!sgroup) {
  383 |       return;
  384 |     }
  385 |     unsigned int id = ParseSGroupIntField(ok, strictParsing, text, line, pos);
  386 |     if (!ok) {
  387 |       sgroup->setIsValid(false);
  388 |       return;
  389 |     }
  390 |     if (id != 0 && !SubstanceGroupChecks::isSubstanceGroupIdFree(*mol, id)) {
  391 |       std::ostringstream errout;
  392 |       errout << "SGroup ID '" << id
  393 |              << "' is assigned to more than one SGroup, on line " << line;
  394 |       SGroupWarnOrThrow<>(strictParsing, errout.str());
  395 |       sgroup->setIsValid(false);
  396 |       return;
  397 |     }
  398 |
  399 |     sgroup->setProp<unsigned int>("ID", id);
  400 |   }
  401 | }
  402 |
  403 | void ParseSGroupV2000SCNLine(IDX_TO_SGROUP_MAP &sGroupMap, RWMol *mol,
  404 |                              const std::string &text, unsigned int line,
  405 |                              bool strictParsing) {
  406 |   PRECONDITION(mol, "bad mol");
  407 |   PRECONDITION(text.substr(0, 6) == "M  SCN", "bad SCN line");
  408 |
  409 |   unsigned int pos = 6;
  410 |   bool ok;
  411 |   unsigned int nent =
  412 |       ParseSGroupIntField(ok, strictParsing, text, line, pos, true);
  413 |   if (!ok) {
  414 |     return;
  415 |   }
  416 |
  417 |   for (unsigned int ie = 0; ie < nent; ++ie) {
  418 |     if (text.size() < pos + 7) {
  419 |       std::ostringstream errout;
  420 |       errout << "SGroup SCN line too short: '" << text << "' on line " << line;
  421 |       errout << "\n needed: " << pos + 7 << " found: " << text.size();
  422 |       SGroupWarnOrThrow<>(strictParsing, errout.str());
  423 |       return;
  424 |     }
  425 |
  426 |     unsigned int sgIdx =
  427 |         ParseSGroupIntField(ok, strictParsing, text, line, pos);
  428 |     if (!ok) {
  429 |       return;
  430 |     }
  431 |     SubstanceGroup *sgroup = FindSgIdx(sGroupMap, sgIdx, line);
  432 |     if (!sgroup) {
  433 |       return;
  434 |     }
  435 |
  436 |     std::string connect = text.substr(++pos, 2);
  437 |
  438 |     if (!SubstanceGroupChecks::isValidConnectType(connect)) {
  439 |       std::ostringstream errout;
  440 |       errout << "Unsupported SGroup connection type '" << connect
  441 |              << "' on line " << line;
  442 |       SGroupWarnOrThrow<>(strictParsing, errout.str());
  443 |       sgroup->setIsValid(false);
  444 |       return;
  445 |     }
  446 |
  447 |     sgroup->setProp("CONNECT", connect);
  448 |     pos += 3;
  449 |   }
  450 | }
  451 |
  452 | void ParseSGroupV2000SDSLine(IDX_TO_SGROUP_MAP &sGroupMap, RWMol *mol,
  453 |                              const std::string &text, unsigned int line,
  454 |                              bool strictParsing) {
  455 |   PRECONDITION(mol, "bad mol");
  456 |   PRECONDITION(text.substr(0, 10) == "M  SDS EXP", "bad SDS line");
  457 |
  458 |   unsigned int pos = 10;
  459 |   bool ok;
> 460 |   unsigned int nent =
  461 |       ParseSGroupIntField(ok, strictParsing, text, line, pos, true);
  462 |   if (!ok) {
  463 |     return;
  464 |   }
  465 |
  466 |   for (unsigned int ie = 0; ie < nent; ++ie) {
  467 |     if (text.size() < pos + 4) {
  468 |       std::ostringstream errout;
  469 |       errout << "SGroup SDS line too short: '" << text << "' on line " << line;
  470 |       SGroupWarnOrThrow<>(strictParsing, errout.str());
  471 |       return;
  472 |     }
  473 |     unsigned int sgIdx =
  474 |         ParseSGroupIntField(ok, strictParsing, text, line, pos);
  475 |     if (!ok) {
  476 |       return;
  477 |     }
  478 |     SubstanceGroup *sgroup = FindSgIdx(sGroupMap, sgIdx, line);
  479 |     if (!sgroup) {
  480 |       return;
  481 |     }
  482 |
  483 |     sgroup->setProp("ESTATE", "E");
  484 |   }
  485 | }
  486 |
  487 | void ParseSGroupV2000SBVLine(IDX_TO_SGROUP_MAP &sGroupMap, RWMol *mol,
  488 |                              const std::string &text, unsigned int line,
  489 |                              bool strictParsing) {
  490 |   PRECONDITION(mol, "bad mol");
  491 |   PRECONDITION(text.substr(0, 6) == "M  SBV", "bad SBV line");
  492 |
  493 |   unsigned int pos = 6;
  494 |   bool ok;
  495 |   unsigned int sgIdx = ParseSGroupIntField(ok, strictParsing, text, line, pos);
  496 |   if (!ok) {
  497 |     return;
  498 |   }
  499 |   SubstanceGroup *sgroup = FindSgIdx(sGroupMap, sgIdx, line);
  500 |   if (!sgroup) {
  501 |     return;
  502 |   }
  503 |
  504 |   unsigned int bondMark =
  505 |       ParseSGroupIntField(ok, strictParsing, text, line, pos);
  506 |   if (!ok) {
  507 |     sgroup->setIsValid(false);
  508 |     return;
  509 |   }
  510 |   Bond *bond = mol->getUniqueBondWithBookmark(bondMark);
  511 |
  512 |   RDGeom::Point3D vector;
  513 |   if (sgroup->getProp<std::string>("TYPE") == "SUP") {
  514 |     vector.x = ParseSGroupDoubleField(ok, strictParsing, text, line, pos);
  515 |     if (!ok) {
  516 |       sgroup->setIsValid(false);
  517 |       return;
  518 |     }
  519 |     vector.y = ParseSGroupDoubleField(ok, strictParsing, text, line, pos);
  520 |     if (!ok) {
  521 |       sgroup->setIsValid(false);
  522 |       return;
  523 |     }
  524 |     vector.z = 0.;
  525 |   }
  526 |
  527 |   try {
  528 |     sgroup->addCState(bond->getIdx(), vector);
  529 |   } catch (const std::exception &e) {
  530 |     SGroupWarnOrThrow<>(strictParsing, e.what());
  531 |     sgroup->setIsValid(false);
  532 |     return;
  533 |   }
  534 | }
  535 |
  536 | void ParseSGroupV2000SDTLine(IDX_TO_SGROUP_MAP &sGroupMap, RWMol *mol,
  537 |                              const std::string &text, unsigned int line,
  538 |                              bool strictParsing) {
  539 |   PRECONDITION(mol, "bad mol");
  540 |   PRECONDITION(text.substr(0, 6) == "M  SDT", "bad SDT line");
  541 |
  542 |   unsigned int pos = 6;
  543 |   bool ok;
  544 |   unsigned int sgIdx = ParseSGroupIntField(ok, strictParsing, text, line, pos);
  545 |   if (!ok) {
  546 |     return;
  547 |   }
  548 |   SubstanceGroup *sgroup = FindSgIdx(sGroupMap, sgIdx, line);
  549 |   if (!sgroup) {
  550 |     return;
  551 |   }
  552 |
  553 |   std::string fieldName;
  554 |   std::string fieldType;
  555 |   std::string fieldInfo;
  556 |   std::string queryType;
  557 |   std::string queryOp;
  558 |
  559 |   try {
  560 |     fieldName = text.substr(++pos, 30);

Reach line at /src/rdkit/Code/GraphMol/FileParsers/MolSGroupParsing.cpp:460 (observed count 4320).


  363 |       ParseSGroupIntField(ok, strictParsing, text, line, pos, true);
  364 |   if (!ok) {
  365 |     return;
  366 |   }
  367 |
  368 |   for (unsigned int ie = 0; ie < nent; ++ie) {
  369 |     if (text.size() < pos + 8) {
  370 |       std::ostringstream errout;
  371 |       errout << "SGroup SLB line too short: '" << text << "' on line " << line;
  372 |       SGroupWarnOrThrow<>(strictParsing, errout.str());
  373 |       return;
  374 |     }
  375 |
  376 |     unsigned int sgIdx =
  377 |         ParseSGroupIntField(ok, strictParsing, text, line, pos);
  378 |     if (!ok) {
  379 |       return;
  380 |     }
  381 |     SubstanceGroup *sgroup = FindSgIdx(sGroupMap, sgIdx, line);
  382 |     if (!sgroup) {
  383 |       return;
  384 |     }
  385 |     unsigned int id = ParseSGroupIntField(ok, strictParsing, text, line, pos);
  386 |     if (!ok) {
  387 |       sgroup->setIsValid(false);
  388 |       return;
  389 |     }
  390 |     if (id != 0 && !SubstanceGroupChecks::isSubstanceGroupIdFree(*mol, id)) {
  391 |       std::ostringstream errout;
  392 |       errout << "SGroup ID '" << id
  393 |              << "' is assigned to more than one SGroup, on line " << line;
  394 |       SGroupWarnOrThrow<>(strictParsing, errout.str());
  395 |       sgroup->setIsValid(false);
  396 |       return;
  397 |     }
  398 |
  399 |     sgroup->setProp<unsigned int>("ID", id);
  400 |   }
  401 | }
  402 |
  403 | void ParseSGroupV2000SCNLine(IDX_TO_SGROUP_MAP &sGroupMap, RWMol *mol,
  404 |                              const std::string &text, unsigned int line,
  405 |                              bool strictParsing) {
  406 |   PRECONDITION(mol, "bad mol");
  407 |   PRECONDITION(text.substr(0, 6) == "M  SCN", "bad SCN line");
  408 |
  409 |   unsigned int pos = 6;
  410 |   bool ok;
  411 |   unsigned int nent =
  412 |       ParseSGroupIntField(ok, strictParsing, text, line, pos, true);
  413 |   if (!ok) {
  414 |     return;
  415 |   }
  416 |
  417 |   for (unsigned int ie = 0; ie < nent; ++ie) {
  418 |     if (text.size() < pos + 7) {
  419 |       std::ostringstream errout;
  420 |       errout << "SGroup SCN line too short: '" << text << "' on line " << line;
  421 |       errout << "\n needed: " << pos + 7 << " found: " << text.size();
  422 |       SGroupWarnOrThrow<>(strictParsing, errout.str());
  423 |       return;
  424 |     }
  425 |
  426 |     unsigned int sgIdx =
  427 |         ParseSGroupIntField(ok, strictParsing, text, line, pos);
  428 |     if (!ok) {
  429 |       return;
  430 |     }
  431 |     SubstanceGroup *sgroup = FindSgIdx(sGroupMap, sgIdx, line);
  432 |     if (!sgroup) {
  433 |       return;
  434 |     }
  435 |
  436 |     std::string connect = text.substr(++pos, 2);
  437 |
  438 |     if (!SubstanceGroupChecks::isValidConnectType(connect)) {
  439 |       std::ostringstream errout;
  440 |       errout << "Unsupported SGroup connection type '" << connect
  441 |              << "' on line " << line;
  442 |       SGroupWarnOrThrow<>(strictParsing, errout.str());
  443 |       sgroup->setIsValid(false);
  444 |       return;
  445 |     }
  446 |
  447 |     sgroup->setProp("CONNECT", connect);
  448 |     pos += 3;
  449 |   }
  450 | }
  451 |
  452 | void ParseSGroupV2000SDSLine(IDX_TO_SGROUP_MAP &sGroupMap, RWMol *mol,
  453 |                              const std::string &text, unsigned int line,
  454 |                              bool strictParsing) {
  455 |   PRECONDITION(mol, "bad mol");
  456 |   PRECONDITION(text.substr(0, 10) == "M  SDS EXP", "bad SDS line");
  457 |
  458 |   unsigned int pos = 10;
  459 |   bool ok;
  460 |   unsigned int nent =
  461 |       ParseSGroupIntField(ok, strictParsing, text, line, pos, true);
  462 |   if (!ok) {
> 463 |     return;
  464 |   }
  465 |
  466 |   for (unsigned int ie = 0; ie < nent; ++ie) {
  467 |     if (text.size() < pos + 4) {
  468 |       std::ostringstream errout;
  469 |       errout << "SGroup SDS line too short: '" << text << "' on line " << line;
  470 |       SGroupWarnOrThrow<>(strictParsing, errout.str());
  471 |       return;
  472 |     }
  473 |     unsigned int sgIdx =
  474 |         ParseSGroupIntField(ok, strictParsing, text, line, pos);
  475 |     if (!ok) {
  476 |       return;
  477 |     }
  478 |     SubstanceGroup *sgroup = FindSgIdx(sGroupMap, sgIdx, line);
  479 |     if (!sgroup) {
  480 |       return;
  481 |     }
  482 |
  483 |     sgroup->setProp("ESTATE", "E");
  484 |   }
  485 | }
  486 |
  487 | void ParseSGroupV2000SBVLine(IDX_TO_SGROUP_MAP &sGroupMap, RWMol *mol,
  488 |                              const std::string &text, unsigned int line,
  489 |                              bool strictParsing) {
  490 |   PRECONDITION(mol, "bad mol");
  491 |   PRECONDITION(text.substr(0, 6) == "M  SBV", "bad SBV line");
  492 |
  493 |   unsigned int pos = 6;
  494 |   bool ok;
  495 |   unsigned int sgIdx = ParseSGroupIntField(ok, strictParsing, text, line, pos);
  496 |   if (!ok) {
  497 |     return;
  498 |   }
  499 |   SubstanceGroup *sgroup = FindSgIdx(sGroupMap, sgIdx, line);
  500 |   if (!sgroup) {
  501 |     return;
  502 |   }
  503 |
  504 |   unsigned int bondMark =
  505 |       ParseSGroupIntField(ok, strictParsing, text, line, pos);
  506 |   if (!ok) {
  507 |     sgroup->setIsValid(false);
  508 |     return;
  509 |   }
  510 |   Bond *bond = mol->getUniqueBondWithBookmark(bondMark);
  511 |
  512 |   RDGeom::Point3D vector;
  513 |   if (sgroup->getProp<std::string>("TYPE") == "SUP") {
  514 |     vector.x = ParseSGroupDoubleField(ok, strictParsing, text, line, pos);
  515 |     if (!ok) {
  516 |       sgroup->setIsValid(false);
  517 |       return;
  518 |     }
  519 |     vector.y = ParseSGroupDoubleField(ok, strictParsing, text, line, pos);
  520 |     if (!ok) {
  521 |       sgroup->setIsValid(false);
  522 |       return;
  523 |     }
  524 |     vector.z = 0.;
  525 |   }
  526 |
  527 |   try {
  528 |     sgroup->addCState(bond->getIdx(), vector);
  529 |   } catch (const std::exception &e) {
  530 |     SGroupWarnOrThrow<>(strictParsing, e.what());
  531 |     sgroup->setIsValid(false);
  532 |     return;
  533 |   }
  534 | }
  535 |
  536 | void ParseSGroupV2000SDTLine(IDX_TO_SGROUP_MAP &sGroupMap, RWMol *mol,
  537 |                              const std::string &text, unsigned int line,
  538 |                              bool strictParsing) {
  539 |   PRECONDITION(mol, "bad mol");
  540 |   PRECONDITION(text.substr(0, 6) == "M  SDT", "bad SDT line");
  541 |
  542 |   unsigned int pos = 6;
  543 |   bool ok;
  544 |   unsigned int sgIdx = ParseSGroupIntField(ok, strictParsing, text, line, pos);
  545 |   if (!ok) {
  546 |     return;
  547 |   }
  548 |   SubstanceGroup *sgroup = FindSgIdx(sGroupMap, sgIdx, line);
  549 |   if (!sgroup) {
  550 |     return;
  551 |   }
  552 |
  553 |   std::string fieldName;
  554 |   std::string fieldType;
  555 |   std::string fieldInfo;
  556 |   std::string queryType;
  557 |   std::string queryOp;
  558 |
  559 |   try {
  560 |     fieldName = text.substr(++pos, 30);
  561 |     boost::trim_right(fieldName);
  562 |     pos += 30;
  563 |     fieldType = text.substr(pos, 2);

Reach line at /src/rdkit/Code/GraphMol/FileParsers/MolSGroupParsing.cpp:463 (observed count 348).