Skip to content
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

Skip corrupted .acf files in Steam library #4200

Merged

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Sep 27, 2024

Problem

After the v1.35.0 release, several users reported an exception at launch:

Unhandled Exception: ValveKeyValue.KeyValueException: Found end of file when another token type was expected. ---> System.InvalidOperationException: Attempted to finalize object while in state InObjectBetweenKeyAndValue.
   at ValveKeyValue.Deserialization.KV1TextReader.FinalizeCurrentObject(Boolean explicit)
   at ValveKeyValue.Deserialization.KV1TextReader.FinalizeDocument()
   at ValveKeyValue.Deserialization.KV1TextReader.ReadObject()
   --- End of inner exception stack trace ---
   at ValveKeyValue.Deserialization.KV1TextReader.ReadObject()
   at ValveKeyValue.KVSerializer.Deserialize(Stream stream, KVSerializerOptions options)
   at CKAN.SteamLibrary.<>c__DisplayClass3_0.<LibraryPathGames>b__0(String acfFile)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at CKAN.SteamLibrary..ctor()
   at CKAN.GameInstanceManager..ctor(IUser user, IConfiguration configuration)
   at CKAN.CmdLine.MainClass.Execute(GameInstanceManager manager, CommonOptions opts, String[] args)
   at CKAN.CmdLine.MainClass.Main(String[] args)

Cause

@Halbann reports:

I stepped through the code and found it was just one acf file responsible that was just a few hundred null bytes with no text. I don't own the game it was for anymore. I deleted the file and CKAN worked fine after that.

Side note: the file was last modified in 2018 so it had obviously been there corrupted for some time without Steam cleaning it up.

Apparently Steam sometimes corrupts one of the important files in its database and then just leaves it there (in addition to leaving a bunch of empty folders after it disables a DLC, see #4002). (Windows may be partly responsible, since this all-null file strongly is strongly reminiscent of #4078, which our code would never cause if the OS ran it as written.) Once this happens, KeyValueValue.KVSerializer.Deserialize throws an exception when asked to read such a file.

Changes

Now if Deserialize throws an exception, we log a warning and continue with the other .acf files.

We will continue to investigate this as other affected users report back, in case they are experiencing the same issue with different causes, but for now this is one definite problem we can address.

Fixes #4197.

@HebaruSan HebaruSan added Bug Something is not working as intended Easy This is easy to fix Core (ckan.dll) Issues affecting the core part of CKAN labels Sep 27, 2024
@HebaruSan HebaruSan merged commit 286d3eb into KSP-CKAN:master Sep 27, 2024
3 checks passed
@HebaruSan HebaruSan deleted the fix/workaround-steam-corrupted-acf-files branch September 27, 2024 18:36
@kretze
Copy link

kretze commented Sep 27, 2024

Problem found
image

File deleted. CKAN starts without errors


Steam libraries were repeatedly transferred from PC / HDD to newer ones and integrated again.
There must have been some old leftovers there.

@cain666-4u

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Easy This is easy to fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: ValveKeyValue.KeyValueException: Found end of file when another token type was expected
3 participants