mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-15 08:00:52 +00:00
delta-apply: fix sign extension
We compute offsets by executing `off |= (*delta++ << 24)` for multiple constants, where `off` is of type `size_t` and `delta` is of type `unsigned char`. The usual arithmetic conversions (see ISO C89 §3.2.1.5 "Usual arithmetic conversions") kick in here, causing us to promote both operands to `int` and then extending the result to an `unsigned long` when OR'ing it with `off`. The integer promotion to `int` may result in wrong size calculations for big values. Fix the issue by making the constants `unsigned long`, causing both operands to be promoted to `unsigned long`.
This commit is contained in:
parent
1fb8a951b6
commit
cf0396a563
@ -121,13 +121,13 @@ int git__delta_apply(
|
|||||||
size_t off = 0, len = 0;
|
size_t off = 0, len = 0;
|
||||||
|
|
||||||
if (cmd & 0x01) off = *delta++;
|
if (cmd & 0x01) off = *delta++;
|
||||||
if (cmd & 0x02) off |= *delta++ << 8;
|
if (cmd & 0x02) off |= *delta++ << 8UL;
|
||||||
if (cmd & 0x04) off |= *delta++ << 16;
|
if (cmd & 0x04) off |= *delta++ << 16UL;
|
||||||
if (cmd & 0x08) off |= *delta++ << 24;
|
if (cmd & 0x08) off |= *delta++ << 24UL;
|
||||||
|
|
||||||
if (cmd & 0x10) len = *delta++;
|
if (cmd & 0x10) len = *delta++;
|
||||||
if (cmd & 0x20) len |= *delta++ << 8;
|
if (cmd & 0x20) len |= *delta++ << 8UL;
|
||||||
if (cmd & 0x40) len |= *delta++ << 16;
|
if (cmd & 0x40) len |= *delta++ << 16UL;
|
||||||
if (!len) len = 0x10000;
|
if (!len) len = 0x10000;
|
||||||
|
|
||||||
if (base_len < off + len || res_sz < len)
|
if (base_len < off + len || res_sz < len)
|
||||||
|
Loading…
Reference in New Issue
Block a user