Skip to content

Commit 40862c6

Browse files
committed
Fix overflow when resizing path-to-string buffer.
The int version of the buffer size was not updated when the buffer was resized. It's there to prevent a signed/unsigned comparison warning, but it's simpler just to cast the other side of the comparison. There's no problem with the signed-to-unsigned cast since we already know that the result is positive due to the previous check. Fixes #10889.
1 parent a9a495e commit 40862c6

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/_path.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,15 +1047,13 @@ void quad2cubic(double x0, double y0,
10471047
char *__append_to_string(char *p, char **buffer, size_t *buffersize,
10481048
const char *content)
10491049
{
1050-
int buffersize_int = (int)*buffersize;
1051-
10521050
for (const char *i = content; *i; ++i) {
10531051
if (p < *buffer) {
10541052
/* This is just an internal error */
10551053
return NULL;
10561054
}
1057-
if (p - *buffer >= buffersize_int) {
1058-
int diff = p - *buffer;
1055+
if ((size_t)(p - *buffer) >= *buffersize) {
1056+
ptrdiff_t diff = p - *buffer;
10591057
*buffersize *= 2;
10601058
*buffer = (char *)realloc(*buffer, *buffersize);
10611059
if (*buffer == NULL) {

0 commit comments

Comments
 (0)