mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	fix: the server does not crash any more when an invalid backup file is uploaded
This commit is contained in:
		
							parent
							
								
									83d0db0607
								
							
						
					
					
						commit
						409c5f7b75
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -15,3 +15,4 @@ test/ | |||||||
| 
 | 
 | ||||||
| sw.* | sw.* | ||||||
| .DS_STORE | .DS_STORE | ||||||
|  | .idea/* | ||||||
|  | |||||||
| @ -8,6 +8,7 @@ const cron = require('../libs/nodeCron') | |||||||
| const fs = require('../libs/fsExtra') | const fs = require('../libs/fsExtra') | ||||||
| const archiver = require('../libs/archiver') | const archiver = require('../libs/archiver') | ||||||
| const StreamZip = require('../libs/nodeStreamZip') | const StreamZip = require('../libs/nodeStreamZip') | ||||||
|  | const fileUtils = require('../utils/fileUtils') | ||||||
| 
 | 
 | ||||||
| // Utils
 | // Utils
 | ||||||
| const { getFileSize } = require('../utils/fileUtils') | const { getFileSize } = require('../utils/fileUtils') | ||||||
| @ -82,7 +83,7 @@ class BackupManager { | |||||||
|       return res.status(500).send('Invalid backup file') |       return res.status(500).send('Invalid backup file') | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const tempPath = Path.join(this.BackupPath, backupFile.name) |     const tempPath = fileUtils.sanitizeFilename(Path.join(this.BackupPath, backupFile.name)) | ||||||
|     const success = await backupFile.mv(tempPath).then(() => true).catch((error) => { |     const success = await backupFile.mv(tempPath).then(() => true).catch((error) => { | ||||||
|       Logger.error('[BackupManager] Failed to move backup file', path, error) |       Logger.error('[BackupManager] Failed to move backup file', path, error) | ||||||
|       return false |       return false | ||||||
| @ -92,8 +93,14 @@ class BackupManager { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const zip = new StreamZip.async({ file: tempPath }) |     const zip = new StreamZip.async({ file: tempPath }) | ||||||
| 
 |     let entries | ||||||
|     const entries = await zip.entries() |     try { | ||||||
|  |       entries = await zip.entries() | ||||||
|  |     } catch(error){ | ||||||
|  |       // Not a valid zip file
 | ||||||
|  |       Logger.error('[BackupManager] Failed to read backup file - backup might not be a valid .zip file', tempPath, error) | ||||||
|  |       return res.status(400).send('Failed to read backup file - backup might not be a valid .zip file') | ||||||
|  |     } | ||||||
|     if (!Object.keys(entries).includes('absdatabase.sqlite')) { |     if (!Object.keys(entries).includes('absdatabase.sqlite')) { | ||||||
|       Logger.error(`[BackupManager] Invalid backup with no absdatabase.sqlite file - might be a backup created on an old Audiobookshelf server.`) |       Logger.error(`[BackupManager] Invalid backup with no absdatabase.sqlite file - might be a backup created on an old Audiobookshelf server.`) | ||||||
|       return res.status(500).send('Invalid backup with no absdatabase.sqlite file - might be a backup created on an old Audiobookshelf server.') |       return res.status(500).send('Invalid backup with no absdatabase.sqlite file - might be a backup created on an old Audiobookshelf server.') | ||||||
| @ -267,7 +274,7 @@ class BackupManager { | |||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    * @see https://github.com/TryGhost/node-sqlite3/pull/1116
 |    * @see https://github.com/TryGhost/node-sqlite3/pull/1116
 | ||||||
|    * @param {Backup} backup  |    * @param {Backup} backup | ||||||
|    * @promise |    * @promise | ||||||
|    */ |    */ | ||||||
|   backupSqliteDb(backup) { |   backupSqliteDb(backup) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user