Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/LAVFilters.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2012-06-12 19:49:21 +0400
committerHendrik Leppkes <h.leppkes@gmail.com>2012-06-12 19:55:57 +0400
commit18d54d106cb4bb7b009a0c14d206dbef5405b7a6 (patch)
treee468d9f6ed9d18422a5f008c039f3cd425dce4b6 /decoder/LAVAudio
parent4a88c0695074daea972d8f57a31774e593ad1e84 (diff)
Prevent crashes when asked to decode a null packet.
Diffstat (limited to 'decoder/LAVAudio')
-rw-r--r--decoder/LAVAudio/Bitstream.cpp11
-rw-r--r--decoder/LAVAudio/DTSDecoder.cpp9
-rw-r--r--decoder/LAVAudio/LAVAudio.cpp16
-rw-r--r--decoder/LAVAudio/LAVAudio.h2
4 files changed, 17 insertions, 21 deletions
diff --git a/decoder/LAVAudio/Bitstream.cpp b/decoder/LAVAudio/Bitstream.cpp
index 953909da..5b5b8824 100644
--- a/decoder/LAVAudio/Bitstream.cpp
+++ b/decoder/LAVAudio/Bitstream.cpp
@@ -285,19 +285,16 @@ void CLAVAudio::ActivateDTSHDMuxing()
HRESULT CLAVAudio::Bitstream(const BYTE *buffer, int buffsize, int &consumed, HRESULT *hrDeliver)
{
int ret = 0;
- BOOL bEOF = (buffsize == -1);
- if (buffsize == -1) buffsize = 1;
+ BOOL bFlush = (buffer == NULL);
AVPacket avpkt;
av_init_packet(&avpkt);
avpkt.duration = 1;
- ASSERT(buffer || bEOF);
-
// Copy data onto our properly padded data buffer (to avoid overreads)
const uint8_t *pDataBuffer = NULL;
if (!m_bInputPadded) {
- if (!bEOF) {
+ if (!bFlush) {
COPY_TO_BUFFER(buffer, buffsize);
}
pDataBuffer = m_pFFBuffer;
@@ -307,7 +304,7 @@ HRESULT CLAVAudio::Bitstream(const BYTE *buffer, int buffsize, int &consumed, HR
consumed = 0;
while (buffsize > 0) {
- if (bEOF) buffsize = 0;
+ if (bFlush) buffsize = 0;
BYTE *pOut = NULL;
int pOut_size = 0;
@@ -328,7 +325,7 @@ HRESULT CLAVAudio::Bitstream(const BYTE *buffer, int buffsize, int &consumed, HR
m_bUpdateTimeCache = FALSE;
}
- if (!bEOF && used_bytes > 0) {
+ if (!bFlush && used_bytes > 0) {
buffsize -= used_bytes;
pDataBuffer += used_bytes;
consumed += used_bytes;
diff --git a/decoder/LAVAudio/DTSDecoder.cpp b/decoder/LAVAudio/DTSDecoder.cpp
index dbb69dc7..97f77004 100644
--- a/decoder/LAVAudio/DTSDecoder.cpp
+++ b/decoder/LAVAudio/DTSDecoder.cpp
@@ -286,15 +286,14 @@ HRESULT CLAVAudio::DecodeDTS(const BYTE * const buffer, int buffsize, int &consu
HRESULT hr = S_FALSE;
int nPCMLength = 0;
- BOOL bEOF = (buffsize == -1);
- if (buffsize == -1) buffsize = 1;
+ BOOL bFlush = (buffer == NULL);
BufferDetails out;
// Copy data onto our properly padded data buffer (to avoid overreads)
const uint8_t *pDataBuffer = NULL;
if (!m_bInputPadded) {
- if (!bEOF) {
+ if (!bFlush) {
COPY_TO_BUFFER(buffer, buffsize);
}
pDataBuffer = m_pFFBuffer;
@@ -305,7 +304,7 @@ HRESULT CLAVAudio::DecodeDTS(const BYTE * const buffer, int buffsize, int &consu
consumed = 0;
while (buffsize > 0) {
nPCMLength = 0;
- if (bEOF) buffsize = 0;
+ if (bFlush) buffsize = 0;
ASSERT(m_pParser);
@@ -328,7 +327,7 @@ HRESULT CLAVAudio::DecodeDTS(const BYTE * const buffer, int buffsize, int &consu
m_bUpdateTimeCache = FALSE;
}
- if (!bEOF && used_bytes > 0) {
+ if (!bFlush && used_bytes > 0) {
buffsize -= used_bytes;
pDataBuffer += used_bytes;
consumed += used_bytes;
diff --git a/decoder/LAVAudio/LAVAudio.cpp b/decoder/LAVAudio/LAVAudio.cpp
index ff859179..a3c3b0ef 100644
--- a/decoder/LAVAudio/LAVAudio.cpp
+++ b/decoder/LAVAudio/LAVAudio.cpp
@@ -1514,8 +1514,7 @@ HRESULT CLAVAudio::Decode(const BYTE * const buffer, int buffsize, int &consumed
BYTE *tmpProcessBuf = NULL;
HRESULT hr = S_FALSE;
- BOOL bEOF = (buffsize == -1);
- if (buffsize == -1) buffsize = 1;
+ BOOL bFlush = (buffer == NULL);
AVPacket avpkt;
av_init_packet(&avpkt);
@@ -1525,7 +1524,7 @@ HRESULT CLAVAudio::Decode(const BYTE * const buffer, int buffsize, int &consumed
// Copy data onto our properly padded data buffer (to avoid overreads)
const uint8_t *pDataBuffer = NULL;
if (!m_bInputPadded) {
- if (!bEOF) {
+ if (!bFlush) {
COPY_TO_BUFFER(buffer, buffsize);
}
pDataBuffer = m_pFFBuffer;
@@ -1575,9 +1574,9 @@ HRESULT CLAVAudio::Decode(const BYTE * const buffer, int buffsize, int &consumed
#endif
consumed = 0;
- while (buffsize > 0) {
+ while (buffsize > 0 || bFlush) {
got_frame = 0;
- if (bEOF) buffsize = 0;
+ if (bFlush) buffsize = 0;
if (m_pParser) {
BYTE *pOut = NULL;
@@ -1600,7 +1599,7 @@ HRESULT CLAVAudio::Decode(const BYTE * const buffer, int buffsize, int &consumed
m_bUpdateTimeCache = FALSE;
}
- if (!bEOF && used_bytes > 0) {
+ if (!bFlush && used_bytes > 0) {
buffsize -= used_bytes;
pDataBuffer += used_bytes;
consumed += used_bytes;
@@ -1625,8 +1624,9 @@ HRESULT CLAVAudio::Decode(const BYTE * const buffer, int buffsize, int &consumed
} else {
continue;
}
- } else if(bEOF) {
- return S_FALSE;
+ } else if(bFlush) {
+ hr = S_FALSE;
+ break;
} else {
avpkt.data = (uint8_t *)pDataBuffer;
avpkt.size = buffsize;
diff --git a/decoder/LAVAudio/LAVAudio.h b/decoder/LAVAudio/LAVAudio.h
index fce78f0f..fa150be2 100644
--- a/decoder/LAVAudio/LAVAudio.h
+++ b/decoder/LAVAudio/LAVAudio.h
@@ -79,7 +79,7 @@ struct BufferDetails {
// Copy the given data into our buffer, including padding, so broken decoders do not overread and crash
#define COPY_TO_BUFFER(data, size) { \
- if (size > m_nFFBufferSize) { \
+ if (size > m_nFFBufferSize || !m_pFFBuffer) { \
m_nFFBufferSize = size; \
m_pFFBuffer = (BYTE*)av_realloc_f(m_pFFBuffer, m_nFFBufferSize + FF_INPUT_BUFFER_PADDING_SIZE, 1); \
if (!m_pFFBuffer) { \