Skip to content

Commit de08998

Browse files
committed
From Tom Ehlert, gracefully error when attempting to write past 4GB instead of wrapping and causing corruption.
1 parent 42a006b commit de08998

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

kernel/fatfs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,18 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
12431243
return 0;
12441244
}
12451245

1246+
/* prevent overwriting beginning of file when write exceeds 4GB,
1247+
i.e. when overflow of offset occurs, return error on write */
1248+
if (fnp->f_offset + count < fnp->f_offset) /* unsigned overflow */
1249+
{
1250+
if (mode == XFR_WRITE)
1251+
{
1252+
/* can't extend beyond 4G so return '0 byte written, DISK_FULL */
1253+
return DE_HNDLDSKFULL;
1254+
}
1255+
/* else XFR_READ should end automatically at EOF */
1256+
}
1257+
12461258
/* The variable secsize will be used later. */
12471259
secsize = fnp->f_dpb->dpb_secsize;
12481260

0 commit comments

Comments
 (0)