Skip to content

fopen with directories makes fseek throw #60

@mhenschel

Description

@mhenschel

I created an embedded in memory backing store containing a directory with some files in it. In my C++ code I accidentally tried to fopen the directory instead of a file. The fopen works but when I try to seek to the end of the opened file (to get the file size by calling ftell) there is a null reference exception in
"PlayerKernel.lseekImpl"

For example:

  1. This is the directory structure
    /directory/file.txt
  2. This is the code that leads to the bug
    FILE* file=fopen("directory");
    if (file) {
    fseek(File, 0, SEEK_END);
    }

I think opening a directory might be undefined behavior in C++ but throwing exceptions into native C code in an fseek call is a problem. IMHO a reasonable thing to do would be to let the fopen call just fail for directories.

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