Skip to content

Commit

Permalink
fix: skip missing file extraction
Browse files Browse the repository at this point in the history
Missing files were not skipped and could end up extracted with stack
garbage as their bundle IDs, path hashes and offsets/sizes.

This can manifest even with `path_rep` file lists as sometimes files
are just not bundled up as file entries but still have path entries.

We now explicitly skip adding any missing wanted files to the set of
files to extract to properly report and count them.
  • Loading branch information
zao committed Aug 21, 2024
1 parent 6307b38 commit a6ad942
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bun_extract_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,26 @@ int main(int argc, char *argv[]) {

struct extract_info {
std::string path;
uint32_t offset;
uint32_t size;
uint32_t offset{};
uint32_t size{};
};

std::unordered_map<uint32_t, std::vector<extract_info>> bundle_parts_to_extract;
for (auto path : wanted_paths) {
for (auto &path : wanted_paths) {
if (path.front() == '"' && path.back() == '"') {
path = path.substr(1, path.size() - 2);
}

int32_t file_id = BunIndexLookupFileByPath(idx, path.c_str());
if (file_id < 0) {
fprintf(stderr, "Could not find file \"%s\"\n", path.c_str());
continue;
}

uint32_t bundle_id;
uint32_t bundle_id{};

uint64_t path_hash;
extract_info ei;
uint64_t path_hash{};
extract_info ei{};
ei.path = path;

BunIndexFileInfo(idx, file_id, &path_hash, &bundle_id, &ei.offset, &ei.size);
Expand Down

0 comments on commit a6ad942

Please sign in to comment.