fix crash when a packet has null data

This commit is contained in:
wang-bin
2014-10-22 13:06:08 +08:00
parent 8526c7bc40
commit b389119bb4
+10 -6
View File
@@ -262,17 +262,21 @@ bool AVDemuxer::readFrame()
// what about marking packet as invalid and do not use isCorrupt?
pkt->isCorrupt = !!(packet.flags & AV_PKT_FLAG_CORRUPT);
#if NO_PADDING_DATA
pkt->data = QByteArray((const char*)packet.data, packet.size);
pkt->data.clear();
if (packet.data)
pkt->data = QByteArray((const char*)packet.data, packet.size);
#else
/*!
larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
The end of the input buffer avpkt->data should be set to 0 to ensure that no overreading happens for damaged MPEG streams
*/
QByteArray encoded;;
encoded.reserve(packet.size + FF_INPUT_BUFFER_PADDING_SIZE);
encoded.resize(packet.size);
// also copy padding data(usually 0)
memcpy(encoded.data(), packet.data, encoded.capacity());
QByteArray encoded;
if (packet.data) {
encoded.reserve(packet.size + FF_INPUT_BUFFER_PADDING_SIZE);
encoded.resize(packet.size);
// also copy padding data(usually 0)
memcpy(encoded.data(), packet.data, encoded.capacity()); // encoded.capacity() is always > 0 even if packet.data, so must check packet.data null
}
pkt->data = encoded;
#endif //NO_PADDING_DATA
pkt->duration = packet.duration;