diff --git a/Makefile b/Makefile index 2d7c466..25247ab 100644 --- a/Makefile +++ b/Makefile @@ -32,14 +32,14 @@ BIN=$(BUILDDIR)/$(APPNAME) ifeq ($(TARGET),win32) PLATFORM=windows CC=i686-pc-mingw32-gcc - CFLAGS=$(COMMON_CFLAGS) -m32 + CFLAGS=$(COMMON_CFLAGS) -m32 -DWINVER=0x500 LIBS=-lws2_32 -liberty APPNAME=audioextract.exe else ifeq ($(TARGET),win64) PLATFORM=windows CC=x86_64-w64-mingw32-gcc - CFLAGS=$(COMMON_CFLAGS) -m64 + CFLAGS=$(COMMON_CFLAGS) -m64 -DWINVER=0x500 LIBS=-lws2_32 -liberty APPNAME=audioextract64.exe endif diff --git a/src/audioextract_windows.c b/src/audioextract_windows.c index 0658ffb..4d59ad4 100644 --- a/src/audioextract_windows.c +++ b/src/audioextract_windows.c @@ -56,8 +56,7 @@ int extract(const struct extract_options *options, size_t *numfilesptr) goto error; } - filesize.LowPart = GetFileSize(hFile, (LPDWORD)&(filesize.HighPart)); - if (filesize.LowPart == INVALID_FILE_SIZE) + if (!GetFileSizeEx(hFile, &filesize)) { PrintError(options->filepath); goto error; @@ -68,6 +67,13 @@ int extract(const struct extract_options *options, size_t *numfilesptr) printf("%s: Skipping empty file.\n", options->filepath); goto cleanup; } + else if (filesize.QuadPart < 0) + { + fprintf(stderr, "%s: File has negative size (%"PRIi64")?\n", + options->filepath, + filesize.QuadPart); + goto error; + } else if ((uint64_t)filesize.QuadPart <= options->offset) { printf("%s: Skipping file because offset is bigger than file.\n", @@ -93,7 +99,7 @@ int extract(const struct extract_options *options, size_t *numfilesptr) goto error; } - if (do_extract(filedata, filesize.QuadPart, options, numfilesptr)) + if (do_extract(filedata, length, options, numfilesptr)) { goto cleanup; }