summaryrefslogtreecommitdiff
path: root/extmod
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-02-14 16:31:31 -0500
committerDan Halbert <halbert@halwitz.org>2020-02-14 18:33:37 -0500
commite0753c4ad2a20b2feede6fa8732fc60895cd6097 (patch)
tree6b558e4090de7134a9a88c57015051d0d90d5370 /extmod
parentcabc30e9a50e0bf87ab2130b6691d234941865ff (diff)
avoid os.stat() int overflow on smallint-only builds
Diffstat (limited to 'extmod')
-rw-r--r--extmod/vfs_fat.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c
index 60f4393f4..9cb4d9842 100644
--- a/extmod/vfs_fat.c
+++ b/extmod/vfs_fat.c
@@ -345,14 +345,21 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
} else {
mode |= MP_S_IFREG;
}
- mp_uint_t seconds = timeutils_seconds_since_epoch(
- 1980 + ((fno.fdate >> 9) & 0x7f),
- (fno.fdate >> 5) & 0x0f,
- fno.fdate & 0x1f,
- (fno.ftime >> 11) & 0x1f,
- (fno.ftime >> 5) & 0x3f,
- 2 * (fno.ftime & 0x1f)
- );
+#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
+ // On non-longint builds, the number of seconds since 1970 (epoch) is too
+ // large to fit in a smallint, so just return 31-DEC-1999 (0).
+ mp_obj_t seconds = MP_OBJ_NEW_SMALL_INT(946684800);
+#else
+ mp_obj_t seconds = mp_obj_new_int_from_uint(
+ timeutils_seconds_since_epoch(
+ 1980 + ((fno.fdate >> 9) & 0x7f),
+ (fno.fdate >> 5) & 0x0f,
+ fno.fdate & 0x1f,
+ (fno.ftime >> 11) & 0x1f,
+ (fno.ftime >> 5) & 0x3f,
+ 2 * (fno.ftime & 0x1f)
+ ));
+#endif
t->items[0] = MP_OBJ_NEW_SMALL_INT(mode); // st_mode
t->items[1] = MP_OBJ_NEW_SMALL_INT(0); // st_ino
t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // st_dev
@@ -360,9 +367,9 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
t->items[4] = MP_OBJ_NEW_SMALL_INT(0); // st_uid
t->items[5] = MP_OBJ_NEW_SMALL_INT(0); // st_gid
t->items[6] = mp_obj_new_int_from_uint(fno.fsize); // st_size
- t->items[7] = mp_obj_new_int_from_uint(seconds); // st_atime
- t->items[8] = mp_obj_new_int_from_uint(seconds); // st_mtime
- t->items[9] = mp_obj_new_int_from_uint(seconds); // st_ctime
+ t->items[7] = seconds; // st_atime
+ t->items[8] = seconds; // st_mtime
+ t->items[9] = seconds; // st_ctime
return MP_OBJ_FROM_PTR(t);
}