-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Master: fopen with directories makes fseek throw #52
Comments
Hi, |
I've checked crossbridge \ posix \ PlayerKernel.as for a glance, but I don't see any trivial problems so it would be great if you could help fixing the problem / maybe sending a pull request. |
Hi. I'll try my best. May be I can modify the example 07 to show the problem. I also had a look at PlayerKernel.as and the only place where a null ref exception might happen was seeking relative to the end of a file. In this case the length of the array for the file content is accessed to get the file length. If the array doesn't exist it would crash. |
I think that method is protected against null refs. at the beginning.
Can you point to the line where it thrown the excptn.? |
Hi. I have a repro case and a trace log. How can I get the exact line number of the exception being thrown? That would be really helpful. Do I have to build a debug version then? Here is the trace log:
For a repro case I slightly modified sample 07. |
Thats enough, it's possible that it is tricky to get the line number, since you are using a CrossBridge ABCs. Maybe with FlashDeBugger (FDB) but i'm unsure.
where fdentry.bytes is NULL. |
Do you think this would be good enough?
or when there are no bytes it should exit like:
? I'm not really familiar with the C file I/O internals, since coming from an AS3 background ... |
I think it's wrong in the first place that fopen succeeds with a directory. It doesn't make much sense to open a file handle for a directory because you cannot do anything with it. The best solution would be not to create a file handle for directories. I don't know where the code is for that but I can try to find it. |
I'm not sure about how freebsd treats open calls on directories. So I'll first check what's supposed to happen with directories first. I'll report back ... |
I created this repo https://github.com/twistedjoe/testFopen You can use it with : Native OSX and Cygwin
Flash CLI build (still using the real filesystem)
SWF with embedvfs
Native output:
Flash cli output
VFS.swf output
Then it crash with:
Since even the native OSX build seems happy to open a directory in read mode, I don't think it would be necessary to handle this. It does not seem like a bug. Just undefined behaviour in the standard. |
@mhenschel Can you please repost the following issue report, since I have deleted the sourceforge forum. |
OK. I checked my FreeBSD machine. fopen works with directories and seeking simply seems do do nothing. So I think your fix will be sufficient. Thanks for the reminder about the forum post. |
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:
/directory/file.txt
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.
The text was updated successfully, but these errors were encountered: