Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: application crash by clipping the recursion with a limit of 10 #1101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions library/src/helpers/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,12 @@ export class SchemaHelpers {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private static jsonFieldToSchema(value: any): any {
private static jsonFieldToSchema(value: any, MAX_REC = 10): any {
// MAX_REC should never be passed as parameter.
// it is meant for internal recursion limit tracking
if (MAX_REC == 0) {
return {};
}
if (value === undefined || value === null) {
return {
type: 'string',
Expand All @@ -545,7 +550,7 @@ export class SchemaHelpers {
return {
type: 'array',
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
items: value.map((v) => this.jsonFieldToSchema(v)),
items: value.map((v) => this.jsonFieldToSchema(v, MAX_REC - 1)),
[this.extRenderAdditionalInfo]: false,
};
}
Expand All @@ -554,7 +559,7 @@ export class SchemaHelpers {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
properties: Object.entries(value).reduce(
(obj, [k, v]) => {
obj[k] = this.jsonFieldToSchema(v);
obj[k] = this.jsonFieldToSchema(v, MAX_REC - 1);
return obj;
},
{} as Record<string, unknown>,
Expand Down
Loading