Skip to content

Commit 734777a

Browse files
committed
fix(jni): 拦截负值参数导致的边界崩溃
1 parent b7607ef commit 734777a

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/jni/bridge.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ pub export fn Java_me_zhenxin_zmusic_ZMusicPlayer_nativeSeek(
280280
_ = env;
281281
_ = obj;
282282
const h = handleToPtr(handle) orelse return -1;
283+
if (position_ms < 0) {
284+
callback.postEvent(&h.pending_event, .error_occurred);
285+
return -1;
286+
}
283287
h.player.seek(@intCast(position_ms)) catch return -1;
284288
return 0;
285289
}
@@ -429,6 +433,10 @@ pub export fn Java_me_zhenxin_zmusic_ZMusicPlayer_nativeRemoveFromQueue(
429433
_ = env;
430434
_ = obj;
431435
const h = handleToPtr(handle) orelse return;
436+
if (index < 0) {
437+
callback.postEvent(&h.pending_event, .error_occurred);
438+
return;
439+
}
432440
h.player.removeFromQueue(@intCast(index)) catch {
433441
callback.postEvent(&h.pending_event, .error_occurred);
434442
};
@@ -490,6 +498,10 @@ pub export fn Java_me_zhenxin_zmusic_ZMusicPlayer_nativePlayAtIndex(
490498
_ = env;
491499
_ = obj;
492500
const h = handleToPtr(handle) orelse return;
501+
if (index < 0) {
502+
callback.postEvent(&h.pending_event, .error_occurred);
503+
return;
504+
}
493505
h.player.playAtIndex(@intCast(index)) catch {
494506
callback.postEvent(&h.pending_event, .error_occurred);
495507
};
@@ -572,6 +584,10 @@ pub export fn Java_me_zhenxin_zmusic_ZMusicPlayer_nativeGetLyricLineAt(
572584
) ?*jni.JString {
573585
_ = obj;
574586
const h = handleToPtr(handle) orelse return null;
587+
if (time_ms < 0) {
588+
callback.postEvent(&h.pending_event, .error_occurred);
589+
return null;
590+
}
575591
// lyrics_data 为 ?Lyrics,使用 |*lyrics| 获取内部指针
576592
if (h.player.lyrics_data) |*lyrics| {
577593
const idx = lyrics.getLineAt(@intCast(time_ms)) orelse return null;

0 commit comments

Comments
 (0)