diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c b/Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c index 09e583ad45..6224f87b44 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c @@ -237,10 +237,6 @@ sentrycrashfu_readEntireFile(const char *const path, char **data, int *length, i int bytesToRead = maxLength; struct stat st; - if (stat(path, &st) < 0) { - SENTRY_ASYNC_SAFE_LOG_ERROR("Could not stat %s: %s", path, strerror(errno)); - goto done; - } fd = open(path, O_RDONLY); if (fd < 0) { @@ -248,6 +244,11 @@ sentrycrashfu_readEntireFile(const char *const path, char **data, int *length, i goto done; } + if (fstat(fd, &st) < 0) { + SENTRY_ASYNC_SAFE_LOG_ERROR("Could not fstat %s: %s", path, strerror(errno)); + goto done; + } + if (bytesToRead == 0 || bytesToRead >= (int)st.st_size) { bytesToRead = (int)st.st_size; } else if (bytesToRead > 0) {