Skip to content

Commit

Permalink
Merge pull request #19 from recidivism5/recidivism5-fix-BITMAPINFO-ou…
Browse files Browse the repository at this point in the history
…t-of-bounds

Fix BITMAPINFO out of bounds access. Revert to BI_BITFIELDS.
  • Loading branch information
zserge authored May 1, 2023
2 parents 2adefcb + 5a005ec commit d41e734
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fenster.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ FENSTER_API int fenster_loop(struct fenster *f) {
// clang-format off
static const uint8_t FENSTER_KEYCODES[] = {0,27,49,50,51,52,53,54,55,56,57,48,45,61,8,9,81,87,69,82,84,89,85,73,79,80,91,93,10,0,65,83,68,70,71,72,74,75,76,59,39,96,0,92,90,88,67,86,66,78,77,44,46,47,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,17,3,0,20,0,19,0,5,18,4,26,127};
// clang-format on
typedef struct BINFO{
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[3];
}BINFO;
static LRESULT CALLBACK fenster_wndproc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam) {
struct fenster *f = (struct fenster *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
Expand All @@ -178,7 +182,7 @@ static LRESULT CALLBACK fenster_wndproc(HWND hwnd, UINT msg, WPARAM wParam,
HDC memdc = CreateCompatibleDC(hdc);
HBITMAP hbmp = CreateCompatibleBitmap(hdc, f->width, f->height);
HBITMAP oldbmp = SelectObject(memdc, hbmp);
BITMAPINFO bi = {{sizeof(bi), f->width, -f->height, 1, 32, BI_RGB}};
BINFO bi = {{sizeof(bi), f->width, -f->height, 1, 32, BI_BITFIELDS}};
bi.bmiColors[0].rgbRed = 0xff;
bi.bmiColors[1].rgbGreen = 0xff;
bi.bmiColors[2].rgbBlue = 0xff;
Expand Down

0 comments on commit d41e734

Please sign in to comment.