Skip to content

Commit f76f8f4

Browse files
Laurence BankLaurence Bank
authored andcommitted
corrected optimized code to not go past buffer end
1 parent 9056d60 commit f76f8f4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/inflate.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,13 +1200,14 @@ int check_crc;
12001200
uint8_t *pEnd = put+copy;
12011201
int overlap = (int)(intptr_t)(put-from);
12021202
if (overlap >= 4) { // overlap of source/dest won't impede normal copy
1203-
while (put < pEnd) {
1203+
while (put < pEnd-3) { // overwriting the output buffer here would be bad, so respect the true length
12041204
*(uint32_t *)put = *(uint32_t *)from;
12051205
put += 4;
12061206
from += 4;
12071207
}
1208-
// correct for possible overshoot of destination ptr
1209-
put = pEnd;
1208+
while (put < pEnd) { // tail end
1209+
*put++ = *from++;
1210+
}
12101211
} else if (overlap == 1) { // copy 1-byte pattern
12111212
uint32_t pattern = *from;
12121213
pattern = pattern | (pattern << 8);

0 commit comments

Comments
 (0)