Skip to content

Commit 78f01f5

Browse files
committed
Fixed out-of-bound access
1 parent 3debab8 commit 78f01f5

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/core/hexeditor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,12 @@ vector<Match *> HexEditor::findPatterns() {
218218
vector<pair<unsigned long, uint8_t>> HexEditor::compareTo(HexEditor &hexEditor) {
219219
vector<pair<unsigned long, uint8_t>> diff_bytes;
220220

221-
for (unsigned long i = 0; i < this->fileSize; i++) {
221+
//Find who has the smaller file size
222+
unsigned long filesize = this->fileSize;
223+
if (hexEditor.fileSize < filesize)
224+
filesize = hexEditor.fileSize;
225+
226+
for (unsigned long i = 0; i < filesize; i++) {
222227
uint8_t byte_new = hexEditor.getCurrentData()[i];
223228
if (this->getCurrentData()[i] != byte_new) {
224229
diff_bytes.push_back(pair<unsigned long, uint8_t>(i, byte_new));

0 commit comments

Comments
 (0)