Fix: the emojis import function could add more entries than max allowed emoji count.

+ another minor fix.
This commit is contained in:
John Livingston
2024-06-20 11:38:04 +02:00
parent 83dd3130a1
commit a0b4b5f61a
5 changed files with 15 additions and 1 deletions

View File

@ -181,6 +181,16 @@ export class ChannelDetailsService {
public async validateEmojisConfiguration (channelEmojis: ChannelEmojis): Promise<boolean> {
const propertiesError: ValidationError['properties'] = {}
if (channelEmojis.customEmojis.length > maxEmojisPerChannel) {
// This can happen when using the import function.
const validationError = new ValidationError(
'ChannelEmojisValidationError',
await this._registerClientOptions.peertubeHelpers.translate(LOC_TOO_MANY_ENTRIES),
propertiesError
)
throw validationError
}
const seen = new Map<string, true>()
for (const [i, e] of channelEmojis.customEmojis.entries()) {
propertiesError[`emojis.${i}.sn`] = []
@ -233,7 +243,7 @@ export class ChannelDetailsService {
let watchDog = 0
while (i >= 0) {
watchDog++
if (watchDog > maxEmojisPerChannel + 10) { // just to avoid infinite loop
if (watchDog > channelEmojis.customEmojis.length + 10) { // just to avoid infinite loop
throw new Error('Seems we have sent too many emojis, this was not expected')
}
const data: CustomEmojiDefinition[] = customEmojis.slice(0, i + 1) // all elements until first new file