Skip to content

Commit 2f3d553

Browse files
committed
Fix potential issue
1 parent 16ac7b3 commit 2f3d553

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/encoder.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int sampleRate, cb_codec callback, void* userdata)
4242
SKP_uint8 payload[MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES];
4343
SKP_int16 in[FRAME_LENGTH_MS * MAX_API_FS_KHZ * MAX_INPUT_FRAMES];
4444
SKP_int32 encSizeBytes, result;
45-
unsigned char* psRead = pcmData;
45+
unsigned char* psRead = pcmData, *psReadEnd = pcmData + dataLen;
4646
void* psEnc = NULL;
4747

4848
#ifdef _SYSTEM_IS_BIG_ENDIAN
@@ -104,9 +104,17 @@ int sampleRate, cb_codec callback, void* userdata)
104104

105105
/* Read input */
106106
counter = (frameSizeReadFromFile_ms * API_fs_Hz) / 1000;
107+
if (counter > psReadEnd - psRead) {
108+
memset(in, 0x00, sizeof(in));
107109

108-
size_t realrd = counter * sizeof(SKP_int16);
109-
memcpy(in, psRead, realrd); psRead += realrd;
110+
size_t realrd = (psReadEnd - psRead);
111+
memcpy(in, psRead, realrd); psRead += realrd;
112+
}
113+
114+
else {
115+
size_t realrd = counter * sizeof(SKP_int16);
116+
memcpy(in, psRead, realrd); psRead += realrd;
117+
}
110118

111119
#ifdef _SYSTEM_IS_BIG_ENDIAN
112120
swap_endian(in, counter);

0 commit comments

Comments
 (0)