Skip to content

Commit 640fb84

Browse files
authored
Merge pull request #2 from hindercanrun/main
fix big ff's
2 parents 13f6b83 + f9e6779 commit 640fb84

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/unlinker.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ inline const char* XAssetTypeToString(int type)
7676
return "unknown";
7777
}
7878

79+
// TODO: Move this into compression.hpp I guess
80+
size_t find_zlib_header(const unsigned char* data, size_t len)
81+
{
82+
for (size_t i = 0; i + 1 < len; i++)
83+
{
84+
if (data[i] == 0x78 && (data[i + 1] == 0x01 || data[i + 1] == 0x9C || data[i + 1] == 0xDA))
85+
{
86+
return i;
87+
}
88+
}
89+
return SIZE_MAX;
90+
}
91+
7992
int unlink_fastfile(const std::string& infile, const std::string& outdir)
8093
{
8194
std::ifstream fin(infile, std::ios::binary);
@@ -103,11 +116,17 @@ int unlink_fastfile(const std::string& infile, const std::string& outdir)
103116
}
104117
fin.close();
105118

106-
size_t offset = 38;
119+
size_t offset = find_zlib_header(data.get(), flen);
120+
if (offset == SIZE_MAX)
121+
{
122+
std::cerr << "No zlib stream found\n";
123+
return 1;
124+
}
125+
107126
unsigned char* comp = data.get() + offset;
108127
size_t comp_len = flen - offset;
109128

110-
auto decompressed = compression::decompress_data(comp, comp_len, 50 * 1024 * 1024);
129+
auto decompressed = compression::decompress_data(comp, comp_len, static_cast<size_t>(50 * 1024) * 1024);
111130
if (decompressed.empty())
112131
{
113132
std::cerr << "Decompression failed" << std::endl;

0 commit comments

Comments
 (0)