fix: use 64-bit seek/tell in fpack, check ftell errors
This commit is contained in:
+19
-4
@@ -1,3 +1,8 @@
|
|||||||
|
#if !defined(_WIN32)
|
||||||
|
#define _FILE_OFFSET_BITS 64
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "fpk.h"
|
#include "fpk.h"
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
@@ -8,8 +13,12 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define PROGRAM_NAME "fpack.exe"
|
#define PROGRAM_NAME "fpack.exe"
|
||||||
|
#define fpack_fseek64(f, off, whence) _fseeki64((f), (off), (whence))
|
||||||
|
#define fpack_ftell64(f) _ftelli64((f))
|
||||||
#else
|
#else
|
||||||
#define PROGRAM_NAME "fpack"
|
#define PROGRAM_NAME "fpack"
|
||||||
|
#define fpack_fseek64(f, off, whence) fseeko((f), (off_t)(off), (whence))
|
||||||
|
#define fpack_ftell64(f) ftello((f))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FPACK_QUIET (1u << 0)
|
#define FPACK_QUIET (1u << 0)
|
||||||
@@ -92,16 +101,22 @@ static void normalize_path(char *s)
|
|||||||
static void *read_file(const char *path, size_t *out_size)
|
static void *read_file(const char *path, size_t *out_size)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
long len;
|
int64_t len;
|
||||||
void *buf;
|
void *buf;
|
||||||
|
|
||||||
fp = fopen(path, "rb");
|
fp = fopen(path, "rb");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
fseek(fp, 0, SEEK_END);
|
if (fpack_fseek64(fp, 0, SEEK_END) != 0) {
|
||||||
len = ftell(fp);
|
fclose(fp);
|
||||||
fseek(fp, 0, SEEK_SET);
|
return NULL;
|
||||||
|
}
|
||||||
|
len = fpack_ftell64(fp);
|
||||||
|
if (len < 0 || fpack_fseek64(fp, 0, SEEK_SET) != 0) {
|
||||||
|
fclose(fp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
buf = malloc((size_t)len);
|
buf = malloc((size_t)len);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
|
|||||||
Reference in New Issue
Block a user