Skip to content

Commit 80cfac7

Browse files
committed
codal_port/microbit_microphone: Validate duration and rate args.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 8041d86 commit 80cfac7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/codal_port/microbit_microphone.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ static mp_obj_t microbit_microphone_record(mp_uint_t n_args, const mp_obj_t *pos
195195
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
196196
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
197197

198+
// Validate arguments.
199+
if (args[ARG_duration].u_int <= 0) {
200+
mp_raise_ValueError(MP_ERROR_TEXT("duration out of bounds"));
201+
}
202+
if (args[ARG_rate].u_int <= 0) {
203+
mp_raise_ValueError(MP_ERROR_TEXT("rate out of bounds"));
204+
}
205+
198206
// Create the AudioFrame to record into.
199207
size_t size = args[ARG_duration].u_int * args[ARG_rate].u_int / 1000;
200208
microbit_audio_frame_obj_t *audio_frame = microbit_audio_frame_make_new(size, args[ARG_rate].u_int);

0 commit comments

Comments
 (0)