swagger-api / swagger-api/swagger-codegen-generators
Issue: circular reference may cause OOM issue
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
Version: 1.0.38
Scenario: applied by swagger-codegen-3.0.41. If there is a circle dependency exist in the json/yaml, then it could cause OOM.
Details:
What really happens is in DefaultCodegenConfig.fixUpParentAndInterfaces, where there is a todo note in the comment:
// TODO Determine what to do if the parent discriminator name == the grandparent discriminator name
currently there is nothing being done against this condition. However, if it really happens (parent equals parent.parent), the loop will not exit and eventually an OOM would occur due to unlimited expansion of the ArrayList: parent.children.
It is highly recommended to add a check, and at least throw an exception with detailed infomation, in order to avoid OOM and notify the user what is really going wrong.
Full code segment:
CodegenModel parent = codegenModel.parentModel;
// if a discriminator exists on the parent, don't add this child to the inheritance hierarchy
// TODO Determine what to do if the parent discriminator name == the grandparent discriminator name
while (parent != null) {
if (parent.children == null) {
parent.children = new ArrayList<CodegenModel>();
}
parent.children.add(codegenModel); // the list keeps growing
if (parent.discriminator == null) {
parent = allModels.get(parent.parent); // if parent equals parent.parent, then this is a self-reassignment
} else {
parent = null;
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at DefaultCodegenConfig.fixUpParentAndInterfaces and trace how parent, parent.parent, allModels, and parent.children interact in the shown loop. Reproduce a circular inheritance input and verify that processing terminates without unbounded ArrayList growth while clearly reporting the invalid relationship; no test file is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100