@@ -605,7 +605,7 @@ static int open2mmap_flags(int open_flags)
605
605
undefined, and errno is set to something appropriate. The user is responsible
606
606
for doing an munmap(ptr, length) when finished with it. openflags should be
607
607
O_RDONLY or O_RDWR, or O_WRONLY. */
608
- char *mmapfile (char *fname, int *length, int openflags) {
608
+ char *mmapfile (char *fname, s64 *length, int openflags) {
609
609
struct stat st;
610
610
int fd;
611
611
int mmap_flags;
@@ -654,9 +654,10 @@ char *mmapfile(char *fname, int *length, int openflags) {
654
654
655
655
static HANDLE gmap = NULL ;
656
656
657
- char *mmapfile (char *fname, int *length, int openflags) {
657
+ char *mmapfile (char *fname, s64 *length, int openflags) {
658
658
HANDLE fd;
659
659
DWORD mflags, oflags;
660
+ DWORD lowsize, highsize;
660
661
char *fileptr;
661
662
662
663
if (!length || !fname) {
@@ -683,11 +684,18 @@ char *mmapfile(char *fname, int *length, int openflags) {
683
684
if (!fd)
684
685
pfatal (" %s(%u): CreateFile()" , __FILE__, __LINE__);
685
686
686
- *length = (int ) GetFileSize (fd, NULL );
687
+ lowsize = GetFileSize (fd, &highsize);
688
+ if (lowsize == INVALID_FILE_SIZE && GetLastError () != NO_ERROR) {
689
+ pfatal (" %s(%u): GetFileSize(), file '%s'" , __FILE__, __LINE__, fname);
690
+ }
691
+ *length = lowsize + highsize << sizeof (DWORD);
692
+ if (*length < 0 ) {
693
+ fatal (" %s(%u): size too large, file '%s'" , __FILE__, __LINE__, fname);
694
+ }
687
695
688
696
gmap = CreateFileMapping (fd, NULL , mflags, 0 , 0 , NULL );
689
697
if (!gmap) {
690
- pfatal (" %s(%u): CreateFileMapping(), file '%s', length %d , mflags %08lX" ,
698
+ pfatal (" %s(%u): CreateFileMapping(), file '%s', length %I64d , mflags %08lX" ,
691
699
__FILE__, __LINE__, fname, *length, mflags);
692
700
}
693
701
@@ -696,7 +704,7 @@ char *mmapfile(char *fname, int *length, int openflags) {
696
704
pfatal (" %s(%u): MapViewOfFile()" , __FILE__, __LINE__);
697
705
698
706
if (o.debugging > 2 ) {
699
- log_write (LOG_PLAIN, " %s(): fd %08lX, gmap %08lX, fileptr %08lX, length %d \n " ,
707
+ log_write (LOG_PLAIN, " %s(): fd %08lX, gmap %08lX, fileptr %08lX, length %I64d \n " ,
700
708
__func__, (DWORD)fd, (DWORD)gmap, (DWORD)fileptr, *length);
701
709
}
702
710
0 commit comments