Skip to content

Commit 4c736ea

Browse files
committed
extmod,unix: For uos.stat interpret st_size member as an unsigned int.
This prevents large files (eg larger than 2gb on a 32-bit arch) from showing up as having a negative size. Fixes issue micropython#3227.
1 parent b16a755 commit 4c736ea

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

extmod/vfs_fat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
243243
t->items[3] = MP_OBJ_NEW_SMALL_INT(0); // st_nlink
244244
t->items[4] = MP_OBJ_NEW_SMALL_INT(0); // st_uid
245245
t->items[5] = MP_OBJ_NEW_SMALL_INT(0); // st_gid
246-
t->items[6] = MP_OBJ_NEW_SMALL_INT(fno.fsize); // st_size
246+
t->items[6] = mp_obj_new_int_from_uint(fno.fsize); // st_size
247247
t->items[7] = MP_OBJ_NEW_SMALL_INT(seconds); // st_atime
248248
t->items[8] = MP_OBJ_NEW_SMALL_INT(seconds); // st_mtime
249249
t->items[9] = MP_OBJ_NEW_SMALL_INT(seconds); // st_ctime

unix/modos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) {
5858
t->items[3] = MP_OBJ_NEW_SMALL_INT(sb.st_nlink);
5959
t->items[4] = MP_OBJ_NEW_SMALL_INT(sb.st_uid);
6060
t->items[5] = MP_OBJ_NEW_SMALL_INT(sb.st_gid);
61-
t->items[6] = MP_OBJ_NEW_SMALL_INT(sb.st_size);
61+
t->items[6] = mp_obj_new_int_from_uint(sb.st_size);
6262
t->items[7] = MP_OBJ_NEW_SMALL_INT(sb.st_atime);
6363
t->items[8] = MP_OBJ_NEW_SMALL_INT(sb.st_mtime);
6464
t->items[9] = MP_OBJ_NEW_SMALL_INT(sb.st_ctime);

0 commit comments

Comments
 (0)