Skip to content

Commit

Permalink
Add failing test for MinGW bug
Browse files Browse the repository at this point in the history
The hunt begins.
  • Loading branch information
jchv committed Aug 3, 2024
1 parent d17f3ee commit f1c4478
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v6
- uses: DeterminateSystems/flake-checker-action@v7
- name: Configure
run: nix develop --command make -j8 all
run: nix build
- name: Upload
uses: actions/upload-artifact@v2
with:
name: ijl15.dll
path: out/ijl15.dll
path: result/lib/ijl15.dll
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# Common dependencies
nativeBuildInputs = [
pkgs.makeWrapper
pkgs.bear
pkgs.pkgsCross.mingw32.stdenv.cc
];

Expand All @@ -33,17 +32,23 @@

inherit nativeBuildInputs;

nativeCheckInputs = nativeCheckInputs ++ [ pkgs.wine ];
nativeCheckInputs = nativeCheckInputs ++ [ pkgs.winePackages.minimal ];

FONTCONFIG_FILE = pkgs.makeFontsConf { fontDirectories = [ ]; };

checkPhase = ''
runHook preCheck
export WINEPREFIX="$TMPDIR/.wine"
make check
export WINEPREFIX="$PWD/.wine"
export WINEARCH="win32"
HOME="$PWD" WINEDEBUG="-all" wineboot
HOME="$PWD" WINEDEBUG="fixme-all" make check
runHook postCheck
'';

doCheck = true;

buildPhase = ''
runHook preBuild
Expand Down
9 changes: 7 additions & 2 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void __declspec(naked) _aullshr() {
}
}
#else
void __chkstk_ms(void) { return; }
unsigned long long __stdcall _aullshr(unsigned long long a, long b) { return a >> b; }
#endif

Expand Down Expand Up @@ -151,7 +152,7 @@ PSTR GetSelfPath() {

BOOL FileExists(LPCTSTR szPath) { return GetFileAttributesA(szPath) != INVALID_FILE_ATTRIBUTES; }

LPSTR ReadEntireFile(LPCSTR szPath) {
LPSTR ReadEntireFile(LPCSTR szPath, LPDWORD dwFileSize) {
HANDLE hFile = NULL;
DWORD dwBytesRead = 0, dwBytesToRead = 0;
BOOL bErrorFlag = FALSE;
Expand Down Expand Up @@ -181,6 +182,10 @@ LPSTR ReadEntireFile(LPCSTR szPath) {
dwBytesToRead -= dwBytesRead;
}

if (dwFileSize) {
*dwFileSize = dwBytesRead;
}

CloseHandle(hFile);
return buffer;
}
Expand All @@ -190,7 +195,7 @@ VOID WriteEntireFile(LPCSTR szPath, LPCSTR data, DWORD dwBytesToWrite) {
DWORD dwBytesWritten;
BOOL bErrorFlag = FALSE;

hFile = CreateFileA(szPath, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
hFile = CreateFileA(szPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
FatalError("Error creating file %s.", szPath);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ LPSTR DupStr(LPCSTR src);

// Utility functions
BOOL FileExists(LPCSTR szPath);
LPSTR ReadEntireFile(LPCSTR szPath);
LPSTR ReadEntireFile(LPCSTR szPath, LPDWORD dwFileSize);
VOID WriteEntireFile(LPCSTR szPath, LPCSTR data, DWORD dwBytesToWrite);
VOID FatalError(PCHAR fmt, ...);
VOID Warning(PCHAR fmt, ...);
Expand Down
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void LoadJsonRugburnConfig() {
sizeof(ExampleRugburnConfig) - 1);
json = DupStr(ExampleRugburnConfig);
} else {
json = ReadEntireFile(RugburnConfigFilename);
json = ReadEntireFile(RugburnConfigFilename, NULL);
}
memset(&Config, 0, sizeof(RUGBURNCONFIG));
JsonReadMap(&json, ReadJsonConfigMap);
Expand Down
56 changes: 56 additions & 0 deletions src/exe/test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "../../patch.h"
#include "../../regex.h"

#include "../../../third_party/ijl/ijl.h"

typedef struct _REGEX_TESTCASE {
LPCSTR pattern, replace, text, expected;
} REGEX_TESTCASE;
Expand Down Expand Up @@ -99,6 +101,50 @@ const LPCSTR ld_tests[] = {
"ff259017f476",
};

BOOL ijl15_crash_test() {
JPEG_CORE_PROPERTIES jcp;
DWORD dwWholeImageSize, dwJPGSizeBytes;
PVOID pJPGBytes;
IJLERR jerr;

// Load JPEG into memory
pJPGBytes = ReadEntireFile("third_party/testdata/exception.jpg", &dwJPGSizeBytes);
jerr = ijlInit(&jcp);
if (jerr < 0) {
return FALSE;
}

// Parse JPEG header
jcp.JPGFile = 0;
jcp.JPGBytes = pJPGBytes;
jcp.JPGSizeBytes = dwJPGSizeBytes;
ijlRead(&jcp, IJL_JBUFF_READPARAMS);
if (jerr < 0) {
return FALSE;
}

// Read JPEG image
dwWholeImageSize = jcp.JPGWidth * jcp.JPGHeight * jcp.DIBChannels;
PVOID buffer = AllocMem(dwWholeImageSize);
jcp.DIBColor = IJL_G;
jcp.DIBChannels = 1;
jcp.DIBWidth = jcp.JPGWidth;
jcp.DIBHeight = jcp.JPGHeight;
jcp.DIBPadBytes = 0;
jcp.DIBBytes = buffer;
jerr = ijlRead(&jcp, IJL_JBUFF_READWHOLEIMAGE);
FreeMem(buffer);

// Return success if there was no error
return jerr >= 0;
}

typedef BOOL (*UNIT_TEST)();

const UNIT_TEST unit_tests[] = {
ijl15_crash_test,
};

#define COUNT_OF(x) ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x])))))

extern void __cdecl start(void) {
Expand All @@ -109,6 +155,7 @@ extern void __cdecl start(void) {
totaltests += COUNT_OF(patch_tests);
totaltests += COUNT_OF(dispatch_tests);
totaltests += COUNT_OF(ld_tests);
totaltests += COUNT_OF(unit_tests);

ConsoleLog("1..%d\r\n", totaltests);

Expand Down Expand Up @@ -195,5 +242,14 @@ extern void __cdecl start(void) {
}
}

for (i = 0; i < COUNT_OF(unit_tests); ++i) {
++testnum;
if (unit_tests[i]()) {
ConsoleLog("ok %d - unit test %d\r\n", testnum, i);
} else {
ConsoleLog("not ok %d - unit test %d\r\n", testnum, i);
}
}

Exit(result);
}
Binary file added third_party/testdata/exception.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f1c4478

Please sign in to comment.