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() {
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();
if let Some(stem) = path.file_stem().and_then(|s| s.to_str())
&& !known_ids.contains(stem)

View file

@ -271,7 +271,9 @@ pub async fn scan_directory_with_options(
if let Some(p) = progress {
p.record_error(msg.clone());
}
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());
let track_index = subtitle
.track_index
.map(|i| i32::try_from(i).unwrap_or(i32::MAX));
let offset_ms = i32::try_from(subtitle.offset_ms).unwrap_or(i32::MAX);
.map(|i| {
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
.execute(
"INSERT INTO subtitles (id, media_id, language, format, file_path, \
@ -3809,7 +3821,11 @@ impl StorageBackend for PostgresBackend {
.get()
.await
.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
.execute("UPDATE subtitles SET offset_ms = $1 WHERE id = $2", &[
&offset, &id,

View file

@ -28,7 +28,8 @@ impl TempFileGuard {
impl Drop for TempFileGuard {
fn drop(&mut self) {
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());
}
}