fix(cbx): "Archive too large" error for invalid/corrupt CBX files (#2205)

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
Balázs Szücs
2026-01-08 15:18:40 -07:00
committed by GitHub
parent 15de049f3d
commit 14dcf552bd
2 changed files with 30 additions and 5 deletions
@@ -1,6 +1,8 @@
package com.adityachandel.booklore.service.reader;
import com.adityachandel.booklore.exception.APIException;
import com.adityachandel.booklore.model.dto.settings.AppSettings;
import com.adityachandel.booklore.exception.ApiError;
import com.adityachandel.booklore.model.entity.BookEntity;
import com.adityachandel.booklore.model.entity.LibraryPathEntity;
import com.adityachandel.booklore.repository.BookRepository;
@@ -167,6 +169,22 @@ class CbxReaderServiceTest {
"Page count should be exactly 130 (actual comic pages only)");
}
@Test
void getAvailablePages_whenArchiveIsCorrupt_shouldThrowFileReadError() throws IOException {
Path corruptCbz = tempDir.resolve("corrupt.cbz");
Files.writeString(corruptCbz, "This is not a zip file");
testBook.setFileName(corruptCbz.getFileName().toString());
testBook.getLibraryPath().setPath(tempDir.toString());
APIException exception = assertThrows(APIException.class, () -> service.getAvailablePages(bookId));
assertNotEquals(ApiError.CACHE_TOO_LARGE.getMessage(), exception.getMessage(),
"Should not throw CACHE_TOO_LARGE for a corrupt file");
assertTrue(exception.getMessage().startsWith("Error reading files from path"),
"Should throw FILE_READ_ERROR (message starts with 'Error reading files from path'), actual: '" + exception.getMessage() + "'");
}
private void createTestCbzWithMacOsFiles(File cbzFile) throws IOException {
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(cbzFile))) {
for (int i = 1; i <= 130; i++) {