diff --git a/block/vvfat.c b/block/vvfat.c index 8ffe8b3b9bfaf..a7040248cdead 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -242,7 +242,7 @@ typedef struct mbr_t { } QEMU_PACKED mbr_t; typedef struct direntry_t { - uint8_t name[8 + 3]; + uint8_t name[8 + 3]; /* file name + extension */ uint8_t attributes; uint8_t reserved[2]; uint16_t ctime; @@ -426,6 +426,7 @@ static direntry_t *create_long_filename(BDRVVVFATState *s, const char *filename) else if(offset<22) offset=14+offset-10; else offset=28+offset-22; entry=array_get(&(s->directory),s->directory.next-1-(i/26)); + offset = MIN(offset, sizeof(entry->name) - 1); if (i >= 2 * length + 2) { entry->name[offset] = 0xff; } else if (i % 2 == 0) {