Enhance PE file Rich header detection with null and boundary checks
- Added null pointer and boundary checks in ExtractFeatures method - Prevent potential buffer overread when searching for Rich header signature - Improve robustness of feature extraction for PE file analysis
This commit is contained in:
@@ -289,10 +289,12 @@ std::vector<double> MachineLearning::ExtractFeatures(const uint8_t* buffer,
|
|||||||
const uint32_t* richPtr = reinterpret_cast<const uint32_t*>(
|
const uint32_t* richPtr = reinterpret_cast<const uint32_t*>(
|
||||||
peBuffer + sizeof(IMAGE_DOS_HEADER));
|
peBuffer + sizeof(IMAGE_DOS_HEADER));
|
||||||
size_t maxLen = dosHeader->e_lfanew - sizeof(IMAGE_DOS_HEADER);
|
size_t maxLen = dosHeader->e_lfanew - sizeof(IMAGE_DOS_HEADER);
|
||||||
for (size_t i = 0; i < maxLen / 4 - 1; i++) {
|
if (maxLen > 0 && richPtr != nullptr) {
|
||||||
if (richPtr[i] == 0x68636952) { // "Rich"
|
for (size_t i = 0; i < maxLen / 4 - 1; i++) {
|
||||||
peInfo.hasRich = true;
|
if (richPtr[i] == 0x68636952) { // "Rich"
|
||||||
break;
|
peInfo.hasRich = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user