Commit 3a5e0a91 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Fix the new ARMv8 CRC code for short and unaligned input.

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.
parent ee9e1455
...@@ -29,17 +29,17 @@ pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t len) ...@@ -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 * significantly faster. Process leading bytes so that the loop below
* starts with a pointer aligned to eight bytes. * 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); crc = __crc32cb(crc, *p);
p += 1; p += 1;
} }
if (!PointerIsAligned(p, uint32) && p < pend) if (!PointerIsAligned(p, uint32) && p + 2 <= pend)
{ {
crc = __crc32ch(crc, *(uint16 *) p); crc = __crc32ch(crc, *(uint16 *) p);
p += 2; p += 2;
} }
if (!PointerIsAligned(p, uint64) && p < pend) if (!PointerIsAligned(p, uint64) && p + 4 <= pend)
{ {
crc = __crc32cw(crc, *(uint32 *) p); crc = __crc32cw(crc, *(uint32 *) p);
p += 4; p += 4;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment