Skip to content

Commit b169ea6

Browse files
[#70] Match cah:/ prefix case-insensitively; document whole-file assumption
The content-addressed scheme casing is not guaranteed, so compare the prefix with OrdinalIgnoreCase. Also document why path-only CRC is correct: a cah:/ stream always references the entire resource file, and the offset/size fields only remain for backward compatibility with the older format that packed multiple resources into a single file.
1 parent 5e2854f commit b169ea6

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Analyzer/PPtrAndCrcProcessor.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class PPtrAndCrcProcessor : IDisposable
1616
// Content-addressed stream paths (new ContentDirectory build output) look like
1717
// "cah:/<hash>". The hash already identifies the content, so the path itself is
1818
// folded into the CRC instead of opening the (differently named) resource file.
19+
// Matched case-insensitively since the scheme casing is not guaranteed.
1920
private const string ContentAddressedPrefix = "cah:/";
2021

2122
private SerializedFile m_SerializedFile;
@@ -101,7 +102,13 @@ private void AppendStreamCrc(long offset, int size, string path)
101102
if (m_SkipCrc)
102103
return;
103104

104-
if (path.StartsWith(ContentAddressedPrefix))
105+
// A cah:/ stream always references the entire resource file: the hash in the path
106+
// is the hash of the whole file, so the path uniquely identifies the bytes and we
107+
// fold it into the CRC rather than reading them. The offset/size fields only exist
108+
// for backward compatibility with the older output format that packed multiple
109+
// resources into one file; ContentDirectory builds never do this (offset is 0 and
110+
// size is the full file), which is why ignoring offset/size here is correct.
111+
if (path.StartsWith(ContentAddressedPrefix, StringComparison.OrdinalIgnoreCase))
105112
{
106113
m_Crc32 = Crc32Algorithm.Append(m_Crc32, Encoding.UTF8.GetBytes(path));
107114
return;

0 commit comments

Comments
 (0)