Skip to content

Commit 4e4cb3f

Browse files
authored
Fixup XNNWeightsCache in OSS (#20607)
### Summary Bring the OSS copy of this file into sync with Meta-internal.
1 parent 0cef6de commit 4e4cb3f

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

backends/xnnpack/runtime/XNNWeightsCache.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <fcntl.h>
1414
#include <sys/file.h>
1515
#include <sys/mman.h>
16-
#include <sys/stat.h>
1716
#include <unistd.h>
1817
#include <cerrno>
1918
#endif
@@ -637,12 +636,16 @@ bool XNNWeightsCache::load_packed_cache() {
637636
close(fd);
638637
return false;
639638
}
640-
struct stat st {};
641-
if (fstat(fd, &st) != 0 || st.st_size < 20) {
639+
// Use lseek instead of fstat: fstat is on Apple's Required Reason API
640+
// list (file-timestamp category), which would force every iOS consumer
641+
// of this header to declare a PrivacyInfo reason. lseek is not on the
642+
// list and yields the same byte count for a regular file.
643+
off_t end_off = lseek(fd, 0, SEEK_END);
644+
if (end_off < 20) {
642645
close(fd);
643646
return false;
644647
}
645-
size_t file_size = static_cast<size_t>(st.st_size);
648+
size_t file_size = static_cast<size_t>(end_off);
646649

647650
uint8_t footer[20];
648651
if (pread(fd, footer, 20, file_size - 20) != 20) {

0 commit comments

Comments
 (0)