[Sumover-dev] [svn commit] r4140 - vic/branches/mpeg4/codec

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Tue Apr 8 05:24:44 BST 2008


Author: douglask
Date: Tue Apr  8 05:24:41 2008
New Revision: 4140

Modified:
   vic/branches/mpeg4/codec/packetbuffer.cpp

Log:
Guard against buffer index overruns.


Whenever totalPkts > maxPkts, a segfault in PacketBuffer::clear() was the result.
PacketBuffer::clear() is no longer dependent on totalPkts.
Packet loss might be the cause for an incorrect total packets count?


Modified: vic/branches/mpeg4/codec/packetbuffer.cpp
==============================================================================
--- vic/branches/mpeg4/codec/packetbuffer.cpp	(original)
+++ vic/branches/mpeg4/codec/packetbuffer.cpp	Tue Apr  8 05:24:41 2008
@@ -14,7 +14,7 @@
     maxLen = maxLength;
     stream = new DataBuffer(maxPacket * maxLength);
 
-    for (int i = 0; i < maxPkts; i++) {
+    for (int i = 0; i < maxPkts && i < MAX_PACKETS; i++) {
 	isDataRecv[i] = false;
 	packets[i] = new DataBuffer(maxLen);
 	//std::cout << "allocate databuffer " << i << "\n";
@@ -24,7 +24,7 @@
 PacketBuffer::~PacketBuffer()
 {
     delete stream;
-    for (int i = 0; i < maxPkts; i++)
+    for (int i = 0; i < maxPkts && i < MAX_PACKETS; i++)
 	delete packets[i];
 }
 
@@ -53,7 +53,7 @@
 {
     if (totalPkts == 0)
 	return false;
-    for (int i = 0; i < totalPkts; i++){	
+    for (int i = 0; i < totalPkts && i < MAX_PACKETS; i++){	
 	if (!isDataRecv[i]){
 	    //debug_msg("lost packet %d\n", i);	
 	    return false;
@@ -80,7 +80,7 @@
 
     //int offset = 0;
     //char* dst = stream->getData();
-    for (int i = 0; i < totalPkts; i++) {
+    for (int i = 0; i < totalPkts && i < MAX_PACKETS; i++) {
 	if (isDataRecv[i]) {
 	    //memcpy(dst+offset, packets[i]->getData(), packets[i]->getDataSize() );
 	    //offset+=packets[i]->getDataSize();
@@ -95,10 +95,10 @@
 void PacketBuffer::clear()
 {
     //std::cout << "Total packets " << totalPkts << "\n";
-    for (int i = 0; i < totalPkts; i++) {
+    for (int i = 0; i < maxPkts && i < MAX_PACKETS; i++) {
 	packets[i]->setSize(0);
-	stream->setSize(0);
 	isDataRecv[i] = false;
     }
+    stream->setSize(0);
     totalPkts = 0;
 }



More information about the Sumover-dev mailing list