Merge pull request #8933 from jepler/avoid-out-of-range-msc-read

Prevent out-of-range reads via msc
This commit is contained in:
Dan Halbert 2024-02-16 12:27:49 -05:00 committed by GitHub
commit 17cd6aa956
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -159,6 +159,13 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buff
const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE;
fs_user_mount_t *vfs = get_vfs(lun);
uint32_t disk_block_count;
disk_ioctl(vfs, GET_SECTOR_COUNT, &disk_block_count);
if (lba + block_count > disk_block_count) {
return -1;
}
disk_read(vfs, buffer, lba, block_count);
return block_count * MSC_FLASH_BLOCK_SIZE;