From 2ce9ab8e673c38bbc86e20a63e453918b373742a Mon Sep 17 00:00:00 2001 From: "John \"Juce\" Bruce" Date: Wed, 3 Oct 2012 17:51:21 -0700 Subject: [PATCH] [WVDRM] Fix effectively-unlimited memory usage Change 14f0d to read the maximum buffer size from a device property did not work correctly on Mako and Prime devices, as they did not have the property set, and the code to fall back to a default value was not working. An empty string would be read instead of the default value, resulting in a maximum of zero. Because Widevine Media Kit would then subtract a few megabytes from this, it would underflow, giving a maximum buffer size of several gigabytes. This would lead to the download code trying to pre-buffer the entire, many-gigabyte movie. As the media server's memory usage grew and grew, other programs would become starved for memory, leading to most other processes on the phone being forced to close. Eventually, the playback app, the media server, or some other crucial piece of functionality would be starved, resulting in a crash. The fix is to fix how we get the default, so that when the property is not available, we get a sensible result. We check the return value of property_get. If it is greater than zero, the property was read successfully, and we parse the answer. If it is equal to (or less than) zero, we fall back to the default value. Bug: 7222769 Change-Id: Ie6186a0533036ab8fa45b1e467611d55f7c345ac --- proprietary/wvm/WVMExtractorImpl.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/proprietary/wvm/WVMExtractorImpl.cpp b/proprietary/wvm/WVMExtractorImpl.cpp index c8aae5fd..3318b96c 100644 --- a/proprietary/wvm/WVMExtractorImpl.cpp +++ b/proprietary/wvm/WVMExtractorImpl.cpp @@ -640,10 +640,12 @@ void WVMExtractorImpl::setUID(uid_t uid) size_t WVMExtractorImpl::getStreamCacheSize() const { char value[PROPERTY_VALUE_MAX]; - snprintf(value, sizeof(value), "%d", kDefaultStreamCacheSize); - property_get("ro.com.widevine.cachesize", value, NULL); - return atol(value); + if (property_get("ro.com.widevine.cachesize", value, NULL) > 0) { + return atol(value); + } else { + return kDefaultStreamCacheSize; + } } status_t WVMExtractorImpl::getError() {