fix(asar): correct archive tree lookups and fail loudly on unreadable input

InsertFile resolved the grandparent node instead of the parent.
Reads no longer create phantom directories in the header.
Bound symlink traversal and skip reparse points when crawling.
Locked or unreadable files now abort packing instead of being dropped.
Read headers and integrity blocks with a full-read loop.
Assert the header keeps its size before overwriting the placeholder.
Validate Pickle buffer sizes, payload overflow and negative lengths.
Check CreateSymbolicLink and external tool exit codes.
Drop unused Pickle accessors, TransformedFile and FilesystemFilesAndLinks.Links.
This commit is contained in:
kitbyte
2026-08-29 16:55:55 +03:00
parent f798714f8d
commit 20956c3228
9 changed files with 163 additions and 245 deletions
+4 -11
View File
@@ -9,13 +9,6 @@ namespace AsarSharp.AsarFileSystem
{
public FileType Type { get; set; }
public FileSystemInfo Stat { get; set; }
public TransformedFile Transformed { get; set; }
}
public class TransformedFile
{
public string Path { get; set; }
public FileSystemInfo Stat { get; set; }
}
public enum FileType
@@ -36,7 +29,7 @@ namespace AsarSharp.AsarFileSystem
}
catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException)
{
return null;
throw new IOException($"Failed to read attributes for '{filename}'", ex);
}
bool isDirectory = (attributes & FileAttributes.Directory) == FileAttributes.Directory;
@@ -59,7 +52,6 @@ namespace AsarSharp.AsarFileSystem
foreach (var fullPath in CrawlIterative(dir))
{
var type = DetermineFileType(fullPath);
if (type == null) continue;
metadata[fullPath] = type;
if (type.Type == FileType.Link) links.Add(fullPath);
filenames.Add(fullPath);
@@ -77,7 +69,8 @@ namespace AsarSharp.AsarFileSystem
{
if (string.Equals(filename, link, StringComparison.OrdinalIgnoreCase)) continue;
if (filename.StartsWith(link, StringComparison.OrdinalIgnoreCase))
// Require a separator after the prefix so "…/foobar" does not match link "…/foo".
if (filename.StartsWith(link + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
{
string rel = Extensions.GetRelativePath(link, fileDir);
if (!rel.StartsWith("..", StringComparison.Ordinal))
@@ -120,7 +113,7 @@ namespace AsarSharp.AsarFileSystem
foreach (var entry in entries)
{
result.Add(entry.FullName);
if (entry is DirectoryInfo subDir)
if (entry is DirectoryInfo subDir && (subDir.Attributes & FileAttributes.ReparsePoint) == 0)
stack.Push(subDir);
}
}