magnusja / libaums

Open source library to access USB Mass Storage devices on Android without rooting your device
Apache License 2.0
1.26k stars 270 forks source link

[Bug report]Fat32 file size is not the real size could raise Error #413

Open jehuty1980 opened 6 months ago

jehuty1980 commented 6 months ago

Problem

me.jahnen.libaums.core.driver.scsi.ScsiBlockDevice.kt line 326 require(buffer.remaining() % blockSize == 0) { "buffer.remaining() must be multiple of blockSize!" } This will check the remaining buffer is multiple of the blockSize, but in Fat/Fat32, file size which recorded at x1c offset is the FILE SIZE, not the REAL occupied size.

For the fatfile, it returns the FILE SIZE: (1)me.jahnen.libaums.core.fs.fat32.FatFile.kt, line 54 get() = entry.fileSize (2)me.jahnen.libaums.core.fs.fat32.FatLfnDirectoryEntry.kt, line 117 get() = actualEntry.fileSize (3)me.jahnen.libaums.core.fs.fat32.FatDirectoryEntry.kt, line 282 get() = getUnsignedInt32(FILE_SIZE_OFF)

I think either rewrite the FatFile.fileSize with adding some "round to blockSize" codes, or add a getRealFileSize() function would be OK.