Fix Android directory CRC login crash and record Mi 8 Lite device tests

This commit is contained in:
shen
2026-09-30 17:54:11 -07:00
parent 059ceadec2
commit d45c5c6cf5
5 changed files with 60 additions and 4 deletions
+13 -2
View File
@@ -6,6 +6,7 @@
#include <cstdio>
#include <vector>
#include <sys/stat.h>
namespace
{
@@ -107,10 +108,20 @@ DWORD GetHFILECRC32(HANDLE hFile)
{
// 40250 maps the whole file from offset 0 and CRCs it; the stream position is left where it was.
FILE* fp = static_cast<FILE*>(hFile);
// PORT: Win32 CreateFile(FILE_ATTRIBUTE_NORMAL) rejects directories. POSIX fopen does not;
// Android directory seek offsets can be enormous, so reject them before allocating a buffer.
struct stat info{};
if (!fp || fstat(fileno(fp), &info) != 0 || !S_ISREG(info.st_mode))
return 0;
const long pos = std::ftell(fp);
std::fseek(fp, 0, SEEK_END);
if (pos < 0 || std::fseek(fp, 0, SEEK_END) != 0)
return 0;
const long size = std::ftell(fp);
std::fseek(fp, 0, SEEK_SET);
if (size < 0 || std::fseek(fp, 0, SEEK_SET) != 0)
{
std::fseek(fp, pos, SEEK_SET);
return 0;
}
std::vector<char> data(size > 0 ? size : 0);
const size_t got = data.empty() ? 0 : std::fread(data.data(), 1, data.size(), fp);
std::fseek(fp, pos, SEEK_SET);