Merge pull request #1636 from frank-freihube-rmcan-com/fixTrailingZeros
Trailing zeros in file leading to unexpected file length get set in destination buffer
This commit is contained in:
commit
0e9234dce6
|
@ -1098,9 +1098,20 @@ cfs_read(int fd, void *buf, unsigned size)
|
||||||
|
|
||||||
fdp = &coffee_fd_set[fd];
|
fdp = &coffee_fd_set[fd];
|
||||||
file = fdp->file;
|
file = fdp->file;
|
||||||
|
|
||||||
|
#if COFFEE_IO_SEMANTICS
|
||||||
|
if(fdp->io_flags & CFS_COFFEE_IO_ENSURE_READ_LENGTH) {
|
||||||
|
while(fdp->offset + size > file->end) {
|
||||||
|
((char*)buf)[--size] = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#endif
|
||||||
if(fdp->offset + size > file->end) {
|
if(fdp->offset + size > file->end) {
|
||||||
size = file->end - fdp->offset;
|
size = file->end - fdp->offset;
|
||||||
}
|
}
|
||||||
|
#if COFFEE_IO_SEMANTICS
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* If the file is not modified, read directly from the file extent. */
|
/* If the file is not modified, read directly from the file extent. */
|
||||||
if(!FILE_MODIFIED(file)) {
|
if(!FILE_MODIFIED(file)) {
|
||||||
|
|
|
@ -63,6 +63,15 @@
|
||||||
*/
|
*/
|
||||||
#define CFS_COFFEE_IO_FIRM_SIZE 0x2
|
#define CFS_COFFEE_IO_FIRM_SIZE 0x2
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instruct Coffee to set unused bytes in the destination buffer to zero.
|
||||||
|
* Trailing zeros may cause a wrong file size, this option ensures that
|
||||||
|
* the corresponding bytes get set, so Coffee does not read unexpected data.
|
||||||
|
*
|
||||||
|
* \sa cfs_coffee_set_io_semantics()
|
||||||
|
*/
|
||||||
|
#define CFS_COFFEE_IO_ENSURE_READ_LENGTH 0x4
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* Header for the Coffee file system.
|
* Header for the Coffee file system.
|
||||||
|
|
Loading…
Reference in a new issue