Skip to content

Commit

Permalink
Prevent table creation and addition with result sizes that are too la…
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFdez authored Jun 10, 2024
1 parent 7907630 commit aa02bdb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/module/apps/compendium-browser/tabs/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export abstract class CompendiumBrowserTab {
* By default none, so resuts would only contain the id field. */
storeFields: string[] = [];

/** Maximum size to create a roll table from as a sanity check, erring towards still too large. */
#MAX_TABLE_SIZE = 1000;

constructor(browser: CompendiumBrowser) {
this.browser = browser;
}
Expand Down Expand Up @@ -321,6 +324,17 @@ export abstract class CompendiumBrowserTab {
if (!this.isInitialized) {
throw ErrorPF2e(`Compendium Browser Tab "${this.tabName}" is not initialized!`);
}

if (this.currentIndex.length > this.#MAX_TABLE_SIZE) {
ui.notifications.warn(
game.i18n.format("PF2E.CompendiumBrowser.RollTable.TooManyResults", {
size: this.currentIndex.length,
maxSize: this.#MAX_TABLE_SIZE,
}),
);
return;
}

const content = await renderTemplate("systems/pf2e/templates/compendium-browser/roll-table-dialog.hbs", {
count: this.currentIndex.length,
});
Expand Down Expand Up @@ -348,6 +362,17 @@ export abstract class CompendiumBrowserTab {
if (!this.isInitialized) {
throw ErrorPF2e(`Compendium Browser Tab "${this.tabName}" is not initialized!`);
}

if (this.currentIndex.length > this.#MAX_TABLE_SIZE) {
ui.notifications.warn(
game.i18n.format("PF2E.CompendiumBrowser.RollTable.TooManyResults", {
size: this.currentIndex.length,
maxSize: this.#MAX_TABLE_SIZE,
}),
);
return;
}

const content = await renderTemplate("systems/pf2e/templates/compendium-browser/roll-table-dialog.hbs", {
count: this.currentIndex.length,
rollTables: game.tables.contents,
Expand Down
1 change: 1 addition & 0 deletions static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@
"CreateDialogText": "Create Roll Table with {count} result(s)?",
"CreateLabel": "Create Roll Table",
"SelectTableTitle": "Select Roll Table",
"TooManyResults": "The result list of size {size} is too large. Maximum size is {maxSize}",
"WeightLabel": "Weight"
},
"Settings": {
Expand Down

0 comments on commit aa02bdb

Please sign in to comment.