From 8da07fc1185c7c16bf3210f781678a7f63e7c3a5 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 11 Feb 2024 11:51:15 -0500 Subject: [PATCH] Add sanity check of document length after image conversion, before ydoc conversion --- server/commands/documentImporter.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/commands/documentImporter.ts b/server/commands/documentImporter.ts index 2d9f9ac2a..f014280be 100644 --- a/server/commands/documentImporter.ts +++ b/server/commands/documentImporter.ts @@ -77,6 +77,13 @@ async function documentImporter({ transaction ); + // Sanity check – text cannot possibly be longer than state so if it is, we can short-circuit here + if (text.length > DocumentValidation.maxStateLength) { + throw InvalidRequestError( + `The document "${title}" is too large to import, please reduce the length and try again` + ); + } + // It's better to truncate particularly long titles than fail the import title = truncate(title, { length: DocumentValidation.maxTitleLength });