From 1643e0e287797f99825322124a26c961cca7c6c3 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 26 Dec 2024 01:23:21 -0500 Subject: [PATCH] [Bugfix] metadata.c copy_mp3entry() dest and orig may overlap I meant to add this with the last patch b07d7d6 since it may supply UNBUFFERED_ID3 to the peek function which uses UNBUFFERED_ID3 and will try to copy it back wich is undefined behavior for memcpy Change-Id: I91160570adac22134c84d3b37f8fcecb097d87d6 --- lib/rbcodec/metadata/metadata.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/rbcodec/metadata/metadata.c b/lib/rbcodec/metadata/metadata.c index 0820c649c2..ace252b2ce 100644 --- a/lib/rbcodec/metadata/metadata.c +++ b/lib/rbcodec/metadata/metadata.c @@ -522,8 +522,11 @@ void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig) void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig) { - memcpy(dest, orig, sizeof(struct mp3entry)); - adjust_mp3entry(dest, dest, orig); + if (dest != orig) + { + memcpy(dest, orig, sizeof(struct mp3entry)); + adjust_mp3entry(dest, dest, orig); + } } /* A shortcut to simplify the common task of clearing the struct */