mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 00:51:04 +00:00
fuzz: update harness for ifcopenshell::file rename
ifcviewer-wgpu renamed IfcParse::IfcFile to ifcopenshell::file (header moved to ifcparse/file.h) and Base::toString to Base::to_string. Update the harness and README to match; verified with a syntax-only compile against this branch's headers.
This commit is contained in:
committed by
Thomas Krijnen
parent
257b8a0dda
commit
aab79ccff9
@@ -1,10 +1,11 @@
|
|||||||
# ifcparse_fuzzer
|
# ifcparse_fuzzer
|
||||||
|
|
||||||
A libFuzzer harness for `IfcParse::IfcFile`. It parses fuzzer input entirely
|
A libFuzzer harness for `ifcopenshell::file`. It parses fuzzer input entirely
|
||||||
in-memory (no subprocess, no temp files), then walks every parsed instance
|
in-memory (no subprocess, no temp files), then walks every parsed instance
|
||||||
and calls `toString()` on it to force full lazy attribute evaluation -
|
and calls `to_string()` on it. Constructing the file already tokenizes,
|
||||||
IfcOpenShell only tokenizes/evaluates on demand, so just constructing
|
type-checks, and resolves every attribute of every instance, so
|
||||||
`IfcFile` barely exercises the parser.
|
`to_string()` mainly adds coverage of the reserialization/formatting code
|
||||||
|
path rather than the parser itself.
|
||||||
|
|
||||||
Disabled by default (`BUILD_FUZZERS=OFF`); building it needs Clang, not GCC.
|
Disabled by default (`BUILD_FUZZERS=OFF`); building it needs Clang, not GCC.
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,12 @@
|
|||||||
* *
|
* *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
// libFuzzer entry point for IfcParse::IfcFile. Parses the input entirely
|
// libFuzzer entry point for ifcopenshell::file. Parses the input entirely
|
||||||
// in-memory (no subprocess, no temp files) so a coverage-guided fuzzer can
|
// in-memory (no subprocess, no temp files) so a coverage-guided fuzzer can
|
||||||
// reach the tokenizer and argument parser directly instead of only ever
|
// reach the tokenizer and argument parser directly instead of only ever
|
||||||
// observing IfcConvert's exit code.
|
// observing IfcConvert's exit code.
|
||||||
|
|
||||||
#include "ifcparse/IfcFile.h"
|
#include "ifcparse/file.h"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -35,19 +35,19 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IfcParse::IfcFile file(const_cast<void*>(static_cast<const void*>(data)), static_cast<int>(size));
|
ifcopenshell::file ifc_file(const_cast<void*>(static_cast<const void*>(data)), static_cast<int>(size));
|
||||||
|
|
||||||
if (file.good()) {
|
if (ifc_file.good()) {
|
||||||
// Constructing IfcFile already tokenizes and type-checks every
|
// Constructing the file already tokenizes and type-checks every
|
||||||
// attribute of every instance (and resolves references), so
|
// attribute of every instance (and resolves references), so
|
||||||
// most tokenizer/argument bugs are reachable without going any
|
// most tokenizer/argument bugs are reachable without going any
|
||||||
// further. toString() is still exercised here since
|
// further. to_string() is still exercised here since
|
||||||
// reserialization walks a different code path and may surface
|
// reserialization walks a different code path and may surface
|
||||||
// additional faults.
|
// additional faults.
|
||||||
std::ostringstream discard;
|
std::ostringstream discard;
|
||||||
for (const auto& entity : file) {
|
for (const auto& entity : ifc_file) {
|
||||||
try {
|
try {
|
||||||
entity.second->toString(discard);
|
entity.second.to_string(discard);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
// Malformed attributes are expected on fuzzed input.
|
// Malformed attributes are expected on fuzzed input.
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user