From 91965bca8c1965ff13084072afaf6dc15a32af11 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 3 Sep 2025 03:58:45 -0500 Subject: [PATCH] fix crash when converting to BRR with invalid loop end issue #2671 --- src/engine/brrUtils.c | 2 +- src/engine/sample.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/engine/brrUtils.c b/src/engine/brrUtils.c index 38073fb4b..ff62e5641 100644 --- a/src/engine/brrUtils.c +++ b/src/engine/brrUtils.c @@ -256,7 +256,7 @@ long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigne total+=9; } // encode loop block - if (loopStart>=0) { + if (loopStart>=0 && loopStart=len) { diff --git a/src/engine/sample.cpp b/src/engine/sample.cpp index 2f7d50617..054d2bc4e 100644 --- a/src/engine/sample.cpp +++ b/src/engine/sample.cpp @@ -1479,7 +1479,8 @@ void DivSample::render(unsigned int formatMask) { } } if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_BRR)) { // BRR - int sampleCount=loop?loopEnd:samples; + int sampleCount=isLoopable()?loopEnd:samples; + if (sampleCount>(int)samples) sampleCount=samples; if (!initInternal(DIV_SAMPLE_DEPTH_BRR,sampleCount)) return; brrEncode(data16,dataBRR,sampleCount,loop?loopStart:-1,brrEmphasis,brrNoFilter); }