From ce545a9897c3e7f3e09336f75f7d67f3b632a6b6 Mon Sep 17 00:00:00 2001 From: Yosshi999 Date: Fri, 15 Nov 2024 22:35:19 +0900 Subject: [PATCH] panic / raise error in invalid range such as start > end --- crates/voicevox_core/src/synthesizer.rs | 3 +++ crates/voicevox_core_python_api/src/lib.rs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/crates/voicevox_core/src/synthesizer.rs b/crates/voicevox_core/src/synthesizer.rs index 2e97fbe1c..73b4a6696 100644 --- a/crates/voicevox_core/src/synthesizer.rs +++ b/crates/voicevox_core/src/synthesizer.rs @@ -141,6 +141,9 @@ mod inner { frame_length = audio.frame_length, ); } + if range.start > range.end { + panic!("{range:?} is invalid because start > end",); + } let range = range.start..range.end + 2 * MARGIN; audio.internal_state.slice(ndarray::s![range, ..]) } diff --git a/crates/voicevox_core_python_api/src/lib.rs b/crates/voicevox_core_python_api/src/lib.rs index 3f3a51cb1..25eb2b33f 100644 --- a/crates/voicevox_core_python_api/src/lib.rs +++ b/crates/voicevox_core_python_api/src/lib.rs @@ -718,6 +718,12 @@ mod blocking { audio.frame_length(), ))); } + if start > end { + return Err(PyIndexError::new_err(format!( + "({}, {}) is invalid range because start > end", + start, end, + ))); + } let wav = &self .synthesizer .read()?