limitEngineSize(1073741824), // 1 GB
limitDFASize(1073741824), // 1 GB
limitNFASize(1048576), // 1 MB
- limitLBRSize(1048576) // 1 MB
+ limitLBRSize(1048576), // 1 MB
+ limitApproxMatchingVertices(5000)
{
assert(maxAnchoredRegion < 64); /* a[lm]_log_sum have limited capacity */
}
G_UPDATE(limitDFASize);
G_UPDATE(limitNFASize);
G_UPDATE(limitLBRSize);
+ G_UPDATE(limitApproxMatchingVertices);
#undef G_UPDATE
if (key == "simple_som") {
u32 limitDFASize; //!< max size of a DFA (in bytes)
u32 limitNFASize; //!< max size of an NFA (in bytes)
u32 limitLBRSize; //!< max size of an LBR engine (in bytes)
+
+ // Approximate matching limits.
+ u32 limitApproxMatchingVertices; //!< max number of vertices per graph
};
#ifndef RELEASE_BUILD
}
}
-void make_fuzzy(NGHolder &g, u32 edit_distance, UNUSED const Grey &grey) {
+void make_fuzzy(NGHolder &g, u32 edit_distance, const Grey &grey) {
if (edit_distance == 0) {
return;
}
+
assert(grey.allowApproximateMatching);
assert(grey.maxEditDistance >= edit_distance);
+
ShadowGraph sg(g, edit_distance);
sg.fuzz_graph();
+
+ // For safety, enforce limit on actual vertex count.
+ if (num_vertices(g) > grey.limitApproxMatchingVertices) {
+ DEBUG_PRINTF("built %zu vertices > limit of %u\n", num_vertices(g),
+ grey.limitApproxMatchingVertices);
+ throw ResourceLimitError();
+ }
}
-}
+
+} // namespace ue2