summaryrefslogtreecommitdiff
path: root/plugingui/resource.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2019-03-06 17:28:57 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2019-03-06 17:28:57 +0100
commit5eb47bed81de1326843e1e3bad41addcfed08d4e (patch)
tree215bdc06a67ca880c1b286a098ba6f6e86b1b7a5 /plugingui/resource.cc
parentf536d8479e37b1515ffb5737a9f276976bef3cf0 (diff)
Fix crash if opening Resource with a directory instead of a file.
Diffstat (limited to 'plugingui/resource.cc')
-rw-r--r--plugingui/resource.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/plugingui/resource.cc b/plugingui/resource.cc
index 2435668..432f25d 100644
--- a/plugingui/resource.cc
+++ b/plugingui/resource.cc
@@ -28,11 +28,13 @@
#include <hugin.hpp>
#include <cstdio>
+#include <climits>
// rcgen generated file containing rc_data declaration.
#include "resource_data.h"
-namespace GUI {
+namespace GUI
+{
// Internal resources start with a colon.
static bool nameIsInternal(const std::string& name)
@@ -85,7 +87,17 @@ Resource::Resource(const std::string& name)
std::fclose(fp);
return;
}
- size_t filesize = ftell(fp);
+
+ long filesize = std::ftell(fp);
+
+ // Apparently fseek doesn't fail if fp points to a directory that has been
+ // opened (which doesn't fail either!!) and ftell will then fail by either
+ // returning -1 or LONG_MAX
+ if(filesize == -1L || filesize == LONG_MAX)
+ {
+ std::fclose(fp);
+ return;
+ }
// Reserve space in the string for the data.
externalData.reserve(filesize);