-
-
Notifications
You must be signed in to change notification settings - Fork 118
Logic error in BlbFile.cs:Blb3File.ReadBlocksInfoAndDirectory regarding BundleFile.Node.flags parsing #71
Description
Describe the bug
There is a logical flaw in the Blb3File constructor, specifically within the ReadBlocksInfoAndDirectory method when parsing BundleFile.Node.flags.
The current implementation incorrectly reads file flags for nodes with an index
To be specific, when
// In file AnimeStudio\BlbFile.cs:113
reader.Position = flagInfoOffset;
var flag = reader.ReadUInt32();
if (i >= 0x20)
{
flag = reader.ReadUInt32();//<-
}
m_DirectoryInfo[i].flags = (uint)(flag & (1 << i)) * 4;This might be intentional, but when flag & (1 << i) is meaningless, because the value of variable flag is still the value when flagInfo[32 + i % 32]. This is not what we wanted.
If nodesCount is never greater than 64, this issue may never surface.
However, one thing is certain, flag & (1 << i) makes the flags value depend on sequence, which is completely wrong.
To Reproduce
N/A
Expected behavior
Since I haven't found any cases of using BundleFile.Node.flags in the code yet, perhaps the loading of the flag here can be removed, or can be changed to
// This code fragment is not verified, please check it
reader.Position = flagInfoOffset + ((i >> 5) << 2)
var flag = reader.ReadUInt32();
m_DirectoryInfo[i].flags = (flag >> (i & 0x1f) & 1) << 2;Screenshots
N/A
Version
master branch 4d758ef
Unity Version
N/A
Game/Sample
N/A
Additional context
The right shift wrap-around of integer literals in C# is also implicit and not easy to understand. Perhaps it can be explicitly written as 1 << (i % 32), 1 << (i & 0x1f) or at least write a comment to explain it.