Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-07-15 12:24:59 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-07-15 12:40:27 +0300
commitd2a4a038906ab455b7af4e90d6f183d95a6ba10e (patch)
treef96b87a841555e0a3d1bd2ee2ddd9258027148e3 /source/blender/blenlib
parent576963d7c1e46c0fb59ee4c8741098cf690d0f27 (diff)
Fix reading directory as file content on Linux
Reading a directory as a file on Linux was attempting to allocate LONG_MAX, this happens in template file lists (fix for that coming next).
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/intern/storage.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index bdaa7be60cf..39af73ac175 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -303,12 +303,24 @@ void *BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *
void *mem = NULL;
if (fp) {
- fseek(fp, 0L, SEEK_END);
+ struct stat st;
+ if (fstat(fileno(fp), &st) == -1) {
+ goto finally;
+ }
+ if (S_ISDIR(st.st_mode)) {
+ goto finally;
+ }
+ if (fseek(fp, 0L, SEEK_END) == -1) {
+ goto finally;
+ }
+ /* Don't use the 'st_size' because it may be the symlink. */
const long int filelen = ftell(fp);
if (filelen == -1) {
goto finally;
}
- fseek(fp, 0L, SEEK_SET);
+ if (fseek(fp, 0L, SEEK_SET) == -1) {
+ goto finally;
+ }
mem = MEM_mallocN(filelen + pad_bytes, __func__);
if (mem == NULL) {
@@ -344,12 +356,24 @@ void *BLI_file_read_binary_as_mem(const char *filepath, size_t pad_bytes, size_t
void *mem = NULL;
if (fp) {
- fseek(fp, 0L, SEEK_END);
+ struct stat st;
+ if (fstat(fileno(fp), &st) == -1) {
+ goto finally;
+ }
+ if (S_ISDIR(st.st_mode)) {
+ goto finally;
+ }
+ if (fseek(fp, 0L, SEEK_END) == -1) {
+ goto finally;
+ }
+ /* Don't use the 'st_size' because it may be the symlink. */
const long int filelen = ftell(fp);
if (filelen == -1) {
goto finally;
}
- fseek(fp, 0L, SEEK_SET);
+ if (fseek(fp, 0L, SEEK_SET) == -1) {
+ goto finally;
+ }
mem = MEM_mallocN(filelen + pad_bytes, __func__);
if (mem == NULL) {