From 6e41b9486407264ce97b6d68f7ebe3fe2217dc06 Mon Sep 17 00:00:00 2001 From: Yosshi999 Date: Sun, 27 Oct 2024 00:19:34 +0900 Subject: [PATCH] margin validation --- crates/voicevox_core/src/synthesizer.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/voicevox_core/src/synthesizer.rs b/crates/voicevox_core/src/synthesizer.rs index 8539493ca..08483160d 100644 --- a/crates/voicevox_core/src/synthesizer.rs +++ b/crates/voicevox_core/src/synthesizer.rs @@ -511,12 +511,18 @@ pub(crate) mod blocking { if (clipped_start..clipped_end).is_empty() { return Ok(vec![]); } - // データからはみ出さない安全マージン - let left_margin = min(MARGIN, audio.padding_frame_length + clipped_start); - let right_margin = min( - MARGIN, - audio.padding_frame_length + (audio.frame_length - clipped_end), - ); + // マージンがデータからはみ出さないことを保証 + // cf. https://github.com/VOICEVOX/voicevox_core/pull/854#discussion_r1803691291 + if (MARGIN > audio.padding_frame_length + clipped_start + || MARGIN > audio.padding_frame_length + (audio.frame_length - clipped_end)) + { + return Err(ErrorRepr::RunModel(anyhow::anyhow!( + "Validation error: Too short padding for input" + )) + .into()); + } + let left_margin = MARGIN; + let right_margin = MARGIN; // 安全マージンを追加したデータ上での区間 let slice_start = audio.padding_frame_length + clipped_start - left_margin; let slice_end = audio.padding_frame_length + clipped_end + right_margin;