Skip to content

Commit

Permalink
>2GB sample load crashfix
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitbubsy committed May 12, 2023
1 parent 5bbaed9 commit 77f3001
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/pt2_sample_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ enum
SAMPLETYPE_FLAC
};

bool loadRAWSample(FILE *f, int32_t filesize, moduleSample_t *s);
bool loadIFFSample(FILE *f, int32_t filesize, moduleSample_t *s);
bool loadAIFFSample(FILE *f, int32_t filesize, moduleSample_t *s);
bool loadWAVSample(FILE *f, int32_t filesize, moduleSample_t *s);
bool loadFLACSample(FILE *f, int32_t filesize, moduleSample_t *s);
bool loadRAWSample(FILE *f, uint32_t filesize, moduleSample_t *s);
bool loadIFFSample(FILE *f, uint32_t filesize, moduleSample_t *s);
bool loadAIFFSample(FILE *f, uint32_t filesize, moduleSample_t *s);
bool loadWAVSample(FILE *f, uint32_t filesize, moduleSample_t *s);
bool loadFLACSample(FILE *f, uint32_t filesize, moduleSample_t *s);

static void setSampleTextFromFilename(moduleSample_t *s, char *entryName, const char *ext)
{
Expand Down
4 changes: 2 additions & 2 deletions src/smploaders/pt2_load_aiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static uint32_t getAIFFSampleRate(uint8_t *in)
return (uint32_t)round(dResult);
}

bool loadAIFFSample(FILE *f, int32_t filesize, moduleSample_t *s)
bool loadAIFFSample(FILE *f, uint32_t filesize, moduleSample_t *s)
{
uint8_t sampleRateBytes[10];
uint16_t bitDepth, numChannels;
Expand All @@ -46,7 +46,7 @@ bool loadAIFFSample(FILE *f, int32_t filesize, moduleSample_t *s)
bool unsigned8bit = false;

fseek(f, 12, SEEK_SET);
while (!feof(f) && ftell(f) < filesize-12)
while (!feof(f) && (uint32_t)ftell(f) < filesize-12)
{
uint32_t blockName, blockSize;

Expand Down
2 changes: 1 addition & 1 deletion src/smploaders/pt2_load_flac.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__St
static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 *const buffer[], void *client_data);
static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);

bool loadFLACSample(FILE *f, int32_t filesize, moduleSample_t *s)
bool loadFLACSample(FILE *f, uint32_t filesize, moduleSample_t *s)
{
FLAC__StreamDecoder *decoder = FLAC__stream_decoder_new();
if (decoder == NULL)
Expand Down
4 changes: 2 additions & 2 deletions src/smploaders/pt2_load_iff.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "../pt2_downsample2x.h"
#include "../pt2_audio.h"

bool loadIFFSample(FILE *f, int32_t filesize, moduleSample_t *s)
bool loadIFFSample(FILE *f, uint32_t filesize, moduleSample_t *s)
{
char tmpCharBuf[23];
uint16_t sampleRate;
Expand All @@ -33,7 +33,7 @@ bool loadIFFSample(FILE *f, int32_t filesize, moduleSample_t *s)
uint32_t sampleVolume = 65536; // max volume

fseek(f, 12, SEEK_SET);
while (!feof(f) && ftell(f) < filesize-12)
while (!feof(f) && (uint32_t)ftell(f) < filesize-12)
{
uint32_t blockName, blockSize;

Expand Down
8 changes: 4 additions & 4 deletions src/smploaders/pt2_load_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include "../pt2_structs.h"
#include "../pt2_replayer.h"

bool loadRAWSample(FILE *f, int32_t filesize, moduleSample_t *s)
bool loadRAWSample(FILE *f, uint32_t filesize, moduleSample_t *s)
{
int32_t sampleLength = filesize;
if (sampleLength > config.maxSampleLength)
uint32_t sampleLength = filesize;
if (sampleLength > (uint32_t)config.maxSampleLength)
sampleLength = config.maxSampleLength;

int8_t *smpDataPtr = &song->sampleData[s->offset];
Expand All @@ -20,7 +20,7 @@ bool loadRAWSample(FILE *f, int32_t filesize, moduleSample_t *s)

if (sampleLength & 1)
{
if (++sampleLength > config.maxSampleLength)
if (++sampleLength > (uint32_t)config.maxSampleLength)
sampleLength = config.maxSampleLength;
}

Expand Down
2 changes: 1 addition & 1 deletion src/smploaders/pt2_load_wav.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum
WAV_FORMAT_IEEE_FLOAT = 0x0003
};

bool loadWAVSample(FILE *f, int32_t filesize, moduleSample_t *s)
bool loadWAVSample(FILE *f, uint32_t filesize, moduleSample_t *s)
{
uint16_t audioFormat, numChannels, bitsPerSample;
uint32_t sampleRate;
Expand Down

0 comments on commit 77f3001

Please sign in to comment.