shithub: pt2-clone

Download patch

ref: 5bbaed9d9de1fdbbff75a4e6e860b42feca782fe
parent: fade190b505076ed4e2ff6112228d8196b8c4ee8
author: Olav Sørensen <[email protected]>
date: Fri May 12 19:21:31 EDT 2023

Only decode as much FLAC data as needed

--- a/src/smploaders/pt2_load_flac.c
+++ b/src/smploaders/pt2_load_flac.c
@@ -84,12 +84,7 @@
 	smpBuf16 = NULL;
 	smpBuf24 = NULL;
 
-	if (!FLAC__stream_decoder_process_until_end_of_stream(decoder))
-	{
-		displayErrorMsg("FLAC LOAD ERROR !");
-		goto error;
-	}
-
+	FLAC__stream_decoder_process_until_end_of_stream(decoder);
 	FLAC__stream_decoder_finish(decoder);
 	FLAC__stream_decoder_delete(decoder);
 
@@ -447,9 +442,14 @@
 
 	uint32_t blockSize = frame->header.blocksize;
 
+	bool doAbort = false;
+
 	const uint32_t samplesAllocated = config.maxSampleLength * 2;
-	if (samplesRead+blockSize > samplesAllocated)
+	if (samplesRead+blockSize >= samplesAllocated)
+	{
 		blockSize = samplesAllocated-samplesRead;
+		doAbort = true;
+	}
 	
 	if (blockSize > 0)
 	{
@@ -503,6 +503,9 @@
 
 		samplesRead += blockSize;
 	}
+
+	if (doAbort)
+		return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
 
 	return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;