Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

fix(backend:files): accept unsafe negative inode IDs

johaven8509428d5310
diff --git a/backend/src/applications/files/services/files-queries.service.spec.ts b/backend/src/applications/files/services/files-queries.service.spec.ts
index 45b00e19..b0840202 100644
--- a/backend/src/applications/files/services/files-queries.service.spec.ts
+++ b/backend/src/applications/files/services/files-queries.service.spec.ts
@@ -53,8 +53,8 @@ describe(FilesQueries.name, () => {
await expect(service.getOrCreateSpaceFile(42, file, dbFile)).resolves.toBe(43)
})
- it('accepts a negative inode in strict mode', async () => {
- await expect(service.getOrCreateSpaceFile(-42, file, dbFile, { rejectIdMismatch: true })).resolves.toBe(43)
+ it.each([-42, -13229323909065756])('accepts the negative inode %s in strict mode', async (fileId) => {
+ await expect(service.getOrCreateSpaceFile(fileId, file, dbFile, { rejectIdMismatch: true })).resolves.toBe(43)
expect(select).not.toHaveBeenCalled()
})
})
diff --git a/backend/src/applications/files/utils/files.ts b/backend/src/applications/files/utils/files.ts
index 1c21bc30..8b81f695 100644
--- a/backend/src/applications/files/utils/files.ts
+++ b/backend/src/applications/files/utils/files.ts
@@ -51,7 +51,7 @@ export function sanitizeName(name: string): string {
}
export function assertValidFileId(fileId: number): void {
- if (!Number.isSafeInteger(fileId) || fileId === 0) {
+ if (!Number.isInteger(fileId) || fileId === 0 || (fileId > 0 && !Number.isSafeInteger(fileId))) {
throw new HttpException('Invalid file id', HttpStatus.BAD_REQUEST)
}
}