Add basic protection aginst circular references in pycdas and pycdc.

This fixes the last case of fuzzer errors detected by #572.
This commit is contained in:
Michael Hansen
2025-08-28 16:42:03 -07:00
parent 38799f5cfb
commit 577720302e
2 changed files with 32 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
#include <string>
#include <iostream>
#include <fstream>
#include <unordered_set>
#include "pyc_module.h"
#include "pyc_numeric.h"
#include "bytecode.h"
@@ -73,6 +74,8 @@ static void iprintf(std::ostream& pyc_output, int indent, const char* fmt, ...)
va_end(varargs);
}
static std::unordered_set<PycObject *> out_seen;
void output_object(PycRef<PycObject> obj, PycModule* mod, int indent,
unsigned flags, std::ostream& pyc_output)
{
@@ -81,6 +84,12 @@ void output_object(PycRef<PycObject> obj, PycModule* mod, int indent,
return;
}
if (out_seen.find((PycObject *)obj) != out_seen.end()) {
fputs("WARNING: Circular reference detected\n", stderr);
return;
}
out_seen.insert((PycObject *)obj);
switch (obj->type()) {
case PycObject::TYPE_CODE:
case PycObject::TYPE_CODE2:
@@ -246,6 +255,8 @@ void output_object(PycRef<PycObject> obj, PycModule* mod, int indent,
default:
iprintf(pyc_output, indent, "<TYPE: %d>\n", obj->type());
}
out_seen.erase((PycObject *)obj);
}
int main(int argc, char* argv[])