[vlc-devel] [PATCH] DASH: prevent integer overflow
fyhuel at viotech.net
fyhuel at viotech.net
Thu Feb 23 11:59:55 CET 2012
From: Frédéric Yhuel <fyhuel at viotech.net>
A integer overflow could happen in bandwidth computation, for example if
we have a DASH server and client on the same machine.
---
.../dash/http/HTTPConnectionManager.cpp | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/modules/stream_filter/dash/http/HTTPConnectionManager.cpp b/modules/stream_filter/dash/http/HTTPConnectionManager.cpp
index 1a5e7d0..7ebc4ad 100644
--- a/modules/stream_filter/dash/http/HTTPConnectionManager.cpp
+++ b/modules/stream_filter/dash/http/HTTPConnectionManager.cpp
@@ -107,12 +107,24 @@ int HTTPConnectionManager::read( Chunk *chunk, void *p_buffer, s
this->timeSecSession += time;
this->timeSecChunk += time;
-
+ unsigned long long bytepsAvg;
if(this->timeSecSession > 0)
- this->bpsAvg = (this->bytesReadSession / this->timeSecSession) * 8;
-
+ {
+ /* Integer overflow may happen */
+ bytepsAvg = this->bytesReadSession / this->timeSecSession;
+ if(bytepsAvg > (LONG_MAX / 8))
+ this->bpsAvg = LONG_MAX;
+ else
+ this->bpsAvg = bytepsAvg * 8;
+ }
if(this->timeSecChunk > 0)
- this->bpsLastChunk = (this->bytesReadChunk / this->timeSecChunk) * 8;
+ {
+ bytepsAvg = this->bytesReadChunk / this->timeSecChunk;
+ if(bytepsAvg > (INT_MAX / 8))
+ this->bpsAvg = INT_MAX;
+ else
+ this->bpsAvg = bytepsAvg * 8;
+ }
if(this->bpsAvg < 0 || this->chunkCount < 2)
this->bpsAvg = 0;
--
1.7.5.4
More information about the vlc-devel
mailing list