From 1670fe1c0009dc2da785c0da2cc684b07dfe568c Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 26 Jul 2019 22:27:31 -0700 Subject: [PATCH] Fix memcpy with overlapping regions When moving the unprocessed line to the beginning of the buffer, in rare edge cases where the unprocessed chunk is larger than the processed chunks (which means the lines are very long), the source & target range will overlap. This is undefined as per C standard and triggers ubsan errors. Fix this by using memmove. --- fast_obj.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast_obj.h b/fast_obj.h index 8b12086..bd09b7d 100644 --- a/fast_obj.h +++ b/fast_obj.h @@ -1367,7 +1367,7 @@ fastObjMesh* fast_obj_read(const char* path) /* Copy overflow for next buffer */ bytes = (unsigned int)(end - last); - memcpy(buffer, last, bytes); + memmove(buffer, last, bytes); start = buffer + bytes; }