Fixed a handful of errors when extracting.

Fixed issues with unsquashfs
This commit is contained in:
Caleb J. Gardner
2026-02-07 06:28:27 -06:00
parent 75502da1d0
commit bcfd983f8d
7 changed files with 23 additions and 16 deletions
+3 -7
View File
@@ -30,17 +30,13 @@ pub fn readDir(alloc: std.mem.Allocator, rdr: *Reader, size: u32) ![]Entry {
var cur_red: u32 = 3; // start at 3 due to "." & ".." being counted in the dir size.
var hdr: Header = undefined;
var raw: RawEntry = undefined;
var out: std.ArrayList(Entry) = try .initCapacity(alloc, 25); // Start out with capacity instead of needing to allocate per header.
var out: std.ArrayList(Entry) = try .initCapacity(alloc, 100); // Start out with a decent capacity instead of needing to allocate per header.
errdefer out.deinit(alloc);
while (cur_red < size) {
try rdr.readSliceEndian(Header, @ptrCast(&hdr), .little);
cur_red += @sizeOf(Header);
const count = hdr.count + 1;
if (out.capacity < count) {
// Make sure we have at least 25 capacity past current count.
try out.ensureUnusedCapacity(alloc, ((count % 25) + 2) * 25);
}
for (0..count) |_| {
try out.ensureUnusedCapacity(alloc, hdr.count + 1);
for (0..hdr.count + 1) |_| {
try rdr.readSliceEndian(RawEntry, @ptrCast(&raw), .little);
const name = try alloc.alloc(u8, raw.name_size + 1);
errdefer alloc.free(name);