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
Fix out of memory crash in CArchive #9225
Conversation
@fritsch what do you think? |
CArchive::CArchive(CFile* pFile, int mode) | ||
{ | ||
m_pFile = pFile; | ||
m_iMode = mode; | ||
|
||
m_pBuffer = new uint8_t[CARCHIVE_BUFFER_MAX]; | ||
memset(m_pBuffer, 0, CARCHIVE_BUFFER_MAX); | ||
m_pBuffer = std::make_unique<uint8_t[]>(CARCHIVE_BUFFER_MAX); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
jenkins build this please |
@Paxxi thx for looking into that! |
jenkins build this please @tamland you were right, we should up the level to c++14 on non-windows so we can use make_unique @anaconda gave me some valuable info on why the issue arises and that got me thinking that we should redesign the format a bit. |
I can, although I already delete the cache files every time Kodi is started so there may be no benefit, or testing of whatever needs testing, unless I stop deleting the caches... which presumably this is meant to fix (make unnecessary)? |
I could be totally off-base here: adding a version (which is hard coded - shouldn't it be in version.txt?) is great, but remembering to bump the version just seems to be asking for future problems... what about basing the version on something unique about the version of Kodi that created the cache (hash of (platform + git hash + build date/time + filesize), maybe even MAC address) - then if a different version of Kodi is installed (or the cache files copied to a different device) they automatically won't be re-used. |
@MilhouseVH yes this is supposed to make your cache deletion obsolete. Having a version tag as you describe is more robust but also more work to implement and debug, I feel this is a reasonable compromise to protect against bad things and simplicity. It also allows for independent versioning of archives, not sure if it's worth anything in the real world though. Hopefully people can get in the habit of keeping it up to date like we do with the db version numbers. |
Maybe Kodi needs a "GUID" property that you could access. Not sure if such a thing is needed for UPnP? I'll drop the cache-clearing patch in the next build. |
I'm pretty sure bumping this version will be forgotten very soon. Something automatic like @MilhouseVH suggested would really make sense. |
After thinking about it after @MilhouseVH comments, yes it needs something better, something that's fixed length. Also the current design is bad and only partially solves it. Need to to rework it and try again |
OK I'll drop this form my builds and go back to my old delete-cache-on-start scheme - let me know if/when you have something else to test! |
|
This issue has come up by some user who upgraded from 15.X to 16.0, see http://trac.kodi.tv/ticket/16668. |
Merely commenting as I'm the originator of the ticket mentioned above - ill-informed opinion only, therefore! From my perspective, doesn't this all depend on how much effort it takes to regenerate the cache? Making it persistent through restarts and upgrades is fine if it's a significant cost to regenerate - otherwise, just delete it as above and treat it just as in-flight/runtime only. That's particularly the case for version upgrades if that's going to present a problem (as it did for me). I really don't see any downside with deleting and forcing a rebuild of a temp file after either major or minor upgrades - we already have a first-run pause to upgrade db tables after a major version bump, and it's acceptable to me to do some other housekeeping at the same time (maybe that's what the version-hash conversation above implies: identify a version change, trigger a deletion. Perhaps piggy-back onto a broader "it's an upgrade!" routine? Do you ever get a db upgrade without a version change, for example?). I suppose it also depends on whether the cache files ever expire naturally and what else triggers a rebuild. If they ever go stale and get rebuilt, then that answers the "cost" question and forcing a rebuild more often or under other circumstances is fine. Thanks for everything you guys do, though. Much appreciated. </ $0.02 worth> |
@ProfYaffle sorry about the radio silence, ran out of free time and forgot about this. I agree that getting rid of the caching would be the best solution but it's probably a fair bit of work to speed up the file listing enough to consider it so fixing the cache is the short term stop gap solution for now. I really should try and get some time to fix this before v17 is due. |
Having been caught out (yet again) with old cache causing odd behaviour, could not the simple solution of clearing the cache as part of installation of Kodi be implemented? Maybe not so simple, not an area I am familiar with. Or perhaps as LE does clearing cache on start-up? Version control of cache sounds way too complicated when it could simply be deleted and recreated when (and if) needed. Cache is temporary after all. And we really do need something in v17 or users upgrading from Jarvis will hit problems and not everyone can cope with deleting *.fi files. |
@daveblake deleting the cache only solves some issues, imagine someone restoring a userdata folder from before an upgrade boom, copy userdata to another system boom copy to another system with different version boom, also it's not very complicated, just need to do the work |
Not a problem if *.fi is deleted at application startup. |
@MilhouseVH true but that somewhat diminishes the use of the cache. |
Personally I think the cache should not survive restarts. For me it's ok to wait a few seconds for a list once after having started Kodi. |
What makes sense and what people do are not the same thing :) but concensus so far seems to be nuke the cache so I'll give it another go |
In the very remote past the temp folder also got nuked after restart and it seems that has been "broken" along the way. |
@Paxxi: agreed but I don't think users copy the cache on purpose. It just gets copied along with the userdata they care about (database, profiles, ...). |
…s to avoid crazy memory allocations. Also add some rudimentary boundary checking to avoid crashing on corrupt archives
To keep it simple I changed that path for *.fi files to live in special://temp/archive_cache and at startup we nuke that folder and recreate it empty. |
As a name, |
Picked the name because there's only CArchive serialized stuff on it |
CArchive is probably badly named too! Still prefer Milhouse's suggestion, but hey not going to argue over a name. Great to get the cache nuked :) |
I don't care about the name too much, but much more about this bugfix. As 2016-07-11 10:40 GMT+02:00 Dave Blake notifications@github.com:
Fingerprint: 4606 DA19 EC2E 9A0B 0157 C81B DA07 CF63 1A99 5A9B |
How about "transient files with a heightened risk of deletion"? :) |
It is in a folder called "temp" doesn't that say it all? Everything under temp is temporary :) Maybe I'm old fashioned but long folder names with spaces seem very naff to me. I get you want a folder to delete rather than have the *.fi under temp folder directly, so just call it "cache" maybe? |
jenkins build this please |
This PR is responsibel for all artwork being cached as With this PR:
Without this PR:
Tested on Ubuntu, LibreELEC RPi2 and LibreELEC Generic. |
fix in the works |
Is this working (nuking the cache at startup?) I've rebooted my RPi2 system many times since 24 July but this file remains:
The above cache is stale which has been causing problems with the TV view (new series added yesterday wasn't appearing in the "TV shows" list, but was appearing in "Recently added"). I had to manually remove I've tested with latest master (84d55c1) in builds of LibreELEC RPi2 (build #728) and also Ubuntu x86_64. Neither is nuking If I |
From Ubuntu:
If I delete
is working as expected. However, when the
is not working as expected, or perhaps not working at all - I tried creating |
OK, the problem appears to be that Although this should be logged as an error, https://github.com/xbmc/xbmc/blob/master/xbmc/filesystem/Directory.cpp#L344, nothing is actually logged, presumably because the logging system isn't fully initialised at this point so the error is silently ignored. Note also that Edit: I believe this to be the crux of the matter. When the So it looks like the |
What I get for making assumptions about the method instead of reading the code. Thanks for the investigation, will fix. |
This should fix this issue
size_t is variable sized and if someone copies userdata from a 32-bit to a 64-bit system some string sizes could be quite large as 4 bytes from the string are added onto the size.
I limited everything to 32bit as we likely won't need large items in our archives, also it seems safest compatibility wise.