Discs must be sized in multiples of 512 bytes or odd things happen
In #36 some of the odd errors were due to seeks beyond the end of the disc. This was because the disc was "specially crafted" to be 25GB + 1 byte, which doesn't fit into the normal 512 byte sectors expected of a disc. This lead to reads going beyond the end of the disc etc. If a similarly evil disc is used with `losetup`, it just ignores the last bytes of the disc that don't fit into 512 chunks. This is what that patch does, logging an error at the same time.
This commit is contained in:
@@ -97,6 +97,15 @@ int open_and_mmap(const char* filename, int* out_fd, uint64_t *out_size, void **
|
||||
warn("lseek64() failed");
|
||||
return size;
|
||||
}
|
||||
|
||||
/* If discs are not in multiples of 512, then odd things happen,
|
||||
* resulting in reads/writes past the ends of files.
|
||||
*/
|
||||
if ( size != (size & (~0x1ff))) {
|
||||
warn("file does not fit into 512-byte sectors; the end of the file will be ignored.");
|
||||
size = size & (~0x1ff);
|
||||
}
|
||||
|
||||
if (out_size) {
|
||||
*out_size = size;
|
||||
}
|
||||
|
Reference in New Issue
Block a user