Limited loading files to INT_MAX.
This commit is contained in:
parent
31f41f6ced
commit
5cb731c9cc
@ -201,8 +201,6 @@ struct journal journal(const char *const dir_journal) {
|
|||||||
/* Because it's in a flat array, the pointers are not stable
|
/* Because it's in a flat array, the pointers are not stable
|
||||||
while we are loading it, and we need to store the offsets. */
|
while we are loading it, and we need to store the offsets. */
|
||||||
*v.offset = (uintptr_t)(contents - j.backing.data);
|
*v.offset = (uintptr_t)(contents - j.backing.data);
|
||||||
/* fixme: not representing with int should be a lazy error,
|
|
||||||
since we use `printf`. */
|
|
||||||
}
|
}
|
||||||
d = 0, int_array_clear(&days);
|
d = 0, int_array_clear(&days);
|
||||||
if(chdir("..") == -1) goto catch;
|
if(chdir("..") == -1) goto catch;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#define ARRAY_NAME char
|
#define ARRAY_NAME char
|
||||||
#define ARRAY_TYPE char
|
#define ARRAY_TYPE char
|
||||||
@ -28,10 +29,12 @@ char *text_append_file(struct char_array *text, const char *const fn) {
|
|||||||
assert(text && fn);
|
assert(text && fn);
|
||||||
start = text->size;
|
start = text->size;
|
||||||
if(!(fp = fopen(fn, "r"))) goto catch;
|
if(!(fp = fopen(fn, "r"))) goto catch;
|
||||||
/* Read entire file in chunks. */
|
/* Read entire file in chunks. We don't allow any text file to go over
|
||||||
|
`INT_MAX` because `printf("%.*s", int, char *)` is used. */
|
||||||
do if(!(cursor = char_array_buffer(text, granularity))
|
do if(!(cursor = char_array_buffer(text, granularity))
|
||||||
|| (nread = fread(cursor, 1, granularity, fp), ferror(fp))
|
|| (nread = fread(cursor, 1, granularity, fp), ferror(fp))
|
||||||
|| !char_array_append(text, nread)) goto catch;
|
|| !char_array_append(text, nread)
|
||||||
|
|| text->size - start >= INT_MAX) goto catch;
|
||||||
while(nread == granularity);
|
while(nread == granularity);
|
||||||
/* File to `C` string. */
|
/* File to `C` string. */
|
||||||
if(!(cursor = char_array_new(text))) goto catch;
|
if(!(cursor = char_array_new(text))) goto catch;
|
||||||
|
Loading…
Reference in New Issue
Block a user