]> granicus.if.org Git - postgresql/commitdiff
Fix the new ARMv8 CRC code for short and unaligned input.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 4 Apr 2018 11:40:20 +0000 (14:40 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 4 Apr 2018 11:40:39 +0000 (14:40 +0300)
The code before the main loop, to handle the possible 1-7 unaligned bytes
at the beginning of the input, was broken, and read past the input, if the
the input was very short.

src/port/pg_crc32c_armv8.c

index 12b8bc1f64ab9d8349fba454a8f238bcea7e40c8..b35b0f758c5541fbc1ed5d8e42211aad70ce5aec 100644 (file)
@@ -29,17 +29,17 @@ pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t len)
         * significantly faster. Process leading bytes so that the loop below
         * starts with a pointer aligned to eight bytes.
         */
-       if (!PointerIsAligned(p, uint16) && p < pend)
+       if (!PointerIsAligned(p, uint16) && p + 1 <= pend)
        {
                crc = __crc32cb(crc, *p);
                p += 1;
        }
-       if (!PointerIsAligned(p, uint32) && p < pend)
+       if (!PointerIsAligned(p, uint32) && p + 2 <= pend)
        {
                crc = __crc32ch(crc, *(uint16 *) p);
                p += 2;
        }
-       if (!PointerIsAligned(p, uint64) && p < pend)
+       if (!PointerIsAligned(p, uint64) && p + 4 <= pend)
        {
                crc = __crc32cw(crc, *(uint32 *) p);
                p += 4;