aboutsummaryrefslogtreecommitdiffstats
path: root/src/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/file.c')
-rw-r--r--src/file.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/file.c b/src/file.c
index f784d93..7171f31 100644
--- a/src/file.c
+++ b/src/file.c
@@ -16,6 +16,7 @@
#include <string.h>
#include "file.h"
#include "error.h"
+#include "utf8.h"
#include "utils.h"
// this would belong to loader.c, but we need it in a separated file to be
@@ -47,6 +48,14 @@ blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err)
sb_string_append_len(str, buffer, read_len);
}
fclose(fp);
+
+ if (!blogc_utf8_validate_str(str)) {
+ *err = blogc_error_new_printf(BLOGC_ERROR_LOADER,
+ "File content is not valid UTF-8: %s", path);
+ sb_string_free(str, true);
+ return NULL;
+ }
+
return sb_string_free(str, false);
}