Skip to content

_stat uninitialized if open() a non existing file with file creation permission. #7759

@everslick

Description

@everslick

Board

n.a.

Device Description

n.a.

Hardware Configuration

n.a.

Version

latest master (checkout manually)

IDE Name

n.a.

Operating System

n.a.

Flash frequency

n.a.

PSRAM enabled

yes

Upload speed

n.a.

Description

I believe there is a serious bug in FileImpl constructor https://github.com/espressif/arduino-esp32/blob/master/libraries/FS/src/vfs_api.cpp#L272 when the file does not exist yet, but is allowed to be created (mode[0] != 'r').

In that case _stat stays uninitialized, which can be seen by size() returning garbage, if called right after open(). Furthermore, I 'think' this leads to also _stat.st_blksize being uninitialized which sounds even more scary. ;-)

The best fix would probably be to memset() the _stat member to 0 in the constructor.

Sketch

n.a.

Debug Message

opening CSV file 'foobar.csv' using mode 'a+'
file='foobar.csv', size=1073638176 bytes, position=0

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions