-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Bugfix - prevent Berry path.listfile() crash by limiting to 25 files #18906
Conversation
(cherry picked from commit 81c39a8)
the first casualty of this mod is my 'zap(folder)' function, which now can't complete as it only deletes the first 25 files in folder/subfolders!... but it's better than it killing tas. |
Thanks, although 25 seems a little low. Would it be safe to return at least 50 or 100 ? |
we could estimate, using the max filename len in the TAS file driver of 48, that 100 would take ~5kbytes. Also, what should we use as the 'terminator'? Could we add 'nil' rather than a string - possibly more unique? p.s. I'm guessing it's possible to add a 2nd optional parameter to listdir which could indicate 'start index', then we would not need a new API to get more... |
I tried to recreate your crash, but was unsuccessful.
Not necessarily related, I have rewritten the the MPATH_LISTDIR part to use the newer Arduino API and the speed of the above operation increased dramatically (from >5 seconds to about 700 milliseconds). |
The TAS did not come back in a few minutes, and I did not have serial on it. The particual cam unit is incredibly reliable normally, but having thought about it, it is entirely possible that I was doing as lot in Berry with each file, and it was just taking a VERY long time. |
Maybe you can upload the images while building the firmware to a device with serial. I created another PR today, that makes it more convenient. |
so it truncated at 45 - but that just a berry print truncation - I am guessing. |
Yes, got confused by the heat 😀 The list is intact and has the correct size of 200. |
your PR also avoids the non closure issue, so I'll close this one in favour of yours.... :) |
Description:
During testing, listing a folder with >1000 files on SDCard crashed TAS, and it did not reboot (had to visit the unit).
Unfortunately I'm not able to get a serial log to see what was actually going on; but path.listdir() is simply not designed to handle large quantities, and had a bug whereby it was not closing files.
So this PR limits it to 25 files, and adds a filename
_more
to the end if the limit is reached, as well as closing the files.A longer term solution to listing larger folders would consist of an iteration over the folder from Berry. More thought and discussion needs to go into this before implementation.
The PR is low risk, but does change the behaviour of path.listdir() by limiting the number of files returned - this could affect exisitng users, so please review and change the number 25 as required.
Checklist:
NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass