Skip to content

Commit cb4ec0c

Browse files
committed
cxbe: Fix oob section reads
1 parent da6a0bd commit cb4ec0c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

tools/cxbe/Exe.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "Exe.h"
99

10+
#include <algorithm>
1011
#include <memory.h>
1112
#include <stdio.h>
1213

@@ -130,10 +131,12 @@ Exe::Exe(const char *x_szFilename)
130131

131132
uint32 raw_size = m_SectionHeader[v].m_sizeof_raw;
132133
uint32 raw_addr = m_SectionHeader[v].m_raw_addr;
134+
uint32 virt_size = m_SectionHeader[v].m_virtual_size;
135+
uint32 max_size = std::max(virt_size, raw_size);
133136

134-
m_bzSection[v] = new uint08[raw_size];
137+
m_bzSection[v] = new uint08[max_size];
135138

136-
memset(m_bzSection[v], 0, raw_size);
139+
memset(m_bzSection[v], 0, max_size);
137140

138141
if(raw_size == 0)
139142
{

tools/cxbe/Xbe.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Xbe.h"
1010
#include "Exe.h"
1111

12+
#include <algorithm>
1213
#include <cstdio>
1314
#include <cstring>
1415
#include <locale.h>
@@ -513,8 +514,12 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec
513514
printf("Xbe::Xbe: Generating Section %.04X...", v);
514515

515516
uint32 RawSize = m_SectionHeader[v].dwSizeofRaw;
517+
uint32 VirtSize = m_SectionHeader[v].dwVirtualSize;
518+
uint32 maxSize = std::max(VirtSize, RawSize);
516519

517-
m_bzSection[v] = new uint08[RawSize];
520+
m_bzSection[v] = new uint08[maxSize];
521+
522+
memset(m_bzSection[v], 0, maxSize);
518523

519524
memcpy(m_bzSection[v], x_Exe->m_bzSection[v], RawSize);
520525

0 commit comments

Comments
 (0)