pinakes-core: fix subtitle i32 overflow in postgres

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I3b43f97c96905953fd58f051667c59096a6a6964
This commit is contained in:
raf 2026-03-12 19:41:01 +03:00
commit 6d68a83003
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
4 changed files with 33 additions and 8 deletions

View file

@ -392,7 +392,13 @@ pub async fn cleanup_orphaned_thumbnails(
if thumbnail_dir.exists() { if thumbnail_dir.exists() {
let entries = std::fs::read_dir(thumbnail_dir)?; let entries = std::fs::read_dir(thumbnail_dir)?;
for entry in entries.flatten() { for entry in entries.filter_map(|e| {
e.map_err(|err| {
warn!(error = %err, "failed to read thumbnail directory entry");
err
})
.ok()
}) {
let path = entry.path(); let path = entry.path();
if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) if let Some(stem) = path.file_stem().and_then(|s| s.to_str())
&& !known_ids.contains(stem) && !known_ids.contains(stem)

View file

@ -271,7 +271,9 @@ pub async fn scan_directory_with_options(
if let Some(p) = progress { if let Some(p) = progress {
p.record_error(msg.clone()); p.record_error(msg.clone());
} }
errors.push(msg); if errors.len() < MAX_STORED_ERRORS {
errors.push(msg);
}
}, },
} }
} }

View file

@ -3721,8 +3721,20 @@ impl StorageBackend for PostgresBackend {
.map(|p| p.to_string_lossy().to_string()); .map(|p| p.to_string_lossy().to_string());
let track_index = subtitle let track_index = subtitle
.track_index .track_index
.map(|i| i32::try_from(i).unwrap_or(i32::MAX)); .map(|i| {
let offset_ms = i32::try_from(subtitle.offset_ms).unwrap_or(i32::MAX); i32::try_from(i).map_err(|_| {
PinakesError::InvalidOperation(format!(
"subtitle track_index {i} exceeds i32 range"
))
})
})
.transpose()?;
let offset_ms = i32::try_from(subtitle.offset_ms).map_err(|_| {
PinakesError::InvalidOperation(format!(
"subtitle offset_ms {} exceeds i32 range",
subtitle.offset_ms
))
})?;
client client
.execute( .execute(
"INSERT INTO subtitles (id, media_id, language, format, file_path, \ "INSERT INTO subtitles (id, media_id, language, format, file_path, \
@ -3809,7 +3821,11 @@ impl StorageBackend for PostgresBackend {
.get() .get()
.await .await
.map_err(|e| PinakesError::Database(format!("pool error: {e}")))?; .map_err(|e| PinakesError::Database(format!("pool error: {e}")))?;
let offset = i32::try_from(offset_ms).unwrap_or(i32::MAX); let offset = i32::try_from(offset_ms).map_err(|_| {
PinakesError::InvalidOperation(format!(
"subtitle offset_ms {offset_ms} exceeds i32 range"
))
})?;
client client
.execute("UPDATE subtitles SET offset_ms = $1 WHERE id = $2", &[ .execute("UPDATE subtitles SET offset_ms = $1 WHERE id = $2", &[
&offset, &id, &offset, &id,

View file

@ -28,9 +28,10 @@ impl TempFileGuard {
impl Drop for TempFileGuard { impl Drop for TempFileGuard {
fn drop(&mut self) { fn drop(&mut self) {
if self.0.exists() if self.0.exists()
&& let Err(e) = std::fs::remove_file(&self.0) { && let Err(e) = std::fs::remove_file(&self.0)
warn!("failed to clean up temp file {}: {e}", self.0.display()); {
} warn!("failed to clean up temp file {}: {e}", self.0.display());
}
} }
} }