Skip to content

Commit

Permalink
Fix build for Android AssetManager target(TINYUSDZ_ANDROID_LOAD_FROM_…
Browse files Browse the repository at this point in the history
…ASSETS)
  • Loading branch information
syoyo committed Jun 2, 2024
1 parent 9e76123 commit a2bd8a8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/io-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,23 @@ bool ReadWholeFile(std::vector<uint8_t> *out, std::string *err,
}
return false;
}
size_t size = AAsset_getLength(asset);
if (size == 0) {
off_t len = AAsset_getLength(asset);
if (len <= 0) {
if (err) {
(*err) += "Invalid file size : " + filepath +
" (does the path point to a directory?)";
}
return false;
}
size_t size = size_t(len);

if (size >= filesize_max) {
(*err) += "File size exceeds filesize_max : " + filepath +
" (filesize_max " + std::to_string(filesize_max) + ")";

return false;
}

out->resize(size);
AAsset_read(asset, reinterpret_cast<char *>(&out->at(0)), size);
AAsset_close(asset);
Expand Down Expand Up @@ -400,15 +409,17 @@ bool ReadFileHeader(std::vector<uint8_t> *out, std::string *err,
}
return false;
}
size_t size = AAsset_getLength(asset);
if (size == 0) {
off_t len = AAsset_getLength(asset);
if (len <= 0) {
if (err) {
(*err) += "Invalid file size : " + filepath +
" (does the path point to a directory?)";
}
return false;
}

size_t size = size_t(len);

size = (std::min)(size_t(max_read_bytes), size);
out->resize(size);
AAsset_read(asset, reinterpret_cast<char *>(&out->at(0)), size);
Expand Down

0 comments on commit a2bd8a8

Please sign in to comment.