Skip to content

Commit 84cb7c0

Browse files
author
chaodu-agent
committed
fix(gateway): address review feedback from 普渡法師
1. media.rs: use DimensionError instead of InsufficientMemory for GIF size limit (correct semantic — size cap, not OOM) 2. line.rs: derive audio filename extension from Content-Type instead of hardcoding .m4a 3. telegram.rs: reject non-UTF-8 documents with return None instead of silently corrupting via from_utf8_lossy
1 parent cf7bf6a commit 84cb7c0

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

gateway/src/adapters/line.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,15 @@ async fn download_line_media(
344344
}
345345
}
346346
} else {
347-
// For audio, we don't process, just send as is.
348-
// LINE audio is usually m4a.
349-
(bytes.to_vec(), content_type, format!("{}.m4a", message_id))
347+
// Derive extension from Content-Type
348+
let ext = if content_type.contains("mpeg") || content_type.contains("mp3") {
349+
"mp3"
350+
} else if content_type.contains("ogg") {
351+
"ogg"
352+
} else {
353+
"m4a"
354+
};
355+
(bytes.to_vec(), content_type, format!("{}.{}", message_id, ext))
350356
};
351357

352358
use base64::Engine;

gateway/src/adapters/telegram.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,13 @@ async fn download_telegram_document(
491491
return None;
492492
}
493493

494-
let text = String::from_utf8_lossy(&bytes);
494+
let text = match String::from_utf8(bytes.to_vec()) {
495+
Ok(t) => t,
496+
Err(_) => {
497+
warn!(file_id, file_name, "Telegram document is not valid UTF-8, skipping");
498+
return None;
499+
}
500+
};
495501
use base64::Engine;
496502
let data = base64::engine::general_purpose::STANDARD.encode(text.as_bytes());
497503
info!(file_id, file_name, size = bytes.len(), "Telegram document download successful");

gateway/src/media.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn resize_and_compress(raw: &[u8]) -> Result<(Vec<u8>, String), image::Image
1616
if format == Some(image::ImageFormat::Gif) {
1717
if raw.len() > GIF_MAX_SIZE {
1818
return Err(image::ImageError::Limits(
19-
image::error::LimitError::from_kind(image::error::LimitErrorKind::InsufficientMemory),
19+
image::error::LimitError::from_kind(image::error::LimitErrorKind::DimensionError),
2020
));
2121
}
2222
return Ok((raw.to_vec(), "image/gif".to_string()));

0 commit comments

Comments
 (0)