Report error correctly for the implementation of
StreamInterface::GetData()
Bug: 28889197
Change-Id: Id07755e1b3637f85b6176a59935ad3a5597cfb05
diff --git a/media/jni/android_media_Utils.cpp b/media/jni/android_media_Utils.cpp
index 359ebad..c62d930 100644
--- a/media/jni/android_media_Utils.cpp
+++ b/media/jni/android_media_Utils.cpp
@@ -68,16 +68,19 @@
if (sizeToRead <= kMinSizeToRead) {
sizeToRead = kMinSizeToRead;
}
+
void* tempBuffer = malloc(sizeToRead);
- if (tempBuffer != NULL) {
- size_t bytesRead = mStream->read(tempBuffer, sizeToRead);
- if (bytesRead != sizeToRead) {
- free(tempBuffer);
- return piex::Error::kFail;
- }
- mStreamBuffer.write(tempBuffer, bytesRead);
- free(tempBuffer);
+ if (tempBuffer == NULL) {
+ return piex::Error::kFail;
}
+
+ size_t bytesRead = mStream->read(tempBuffer, sizeToRead);
+ if (bytesRead != sizeToRead) {
+ free(tempBuffer);
+ return piex::Error::kFail;
+ }
+ mStreamBuffer.write(tempBuffer, bytesRead);
+ free(tempBuffer);
}
// Read bytes.
@@ -126,8 +129,8 @@
size_t size = fread((void*)data, sizeof(std::uint8_t), length, mFile);
mPosition += size;
- // Handle errors.
- if (ferror(mFile)) {
+ // Handle errors and verify the size.
+ if (ferror(mFile) || size != length) {
ALOGV("GetData read failed: (offset: %zu, length: %zu)", offset, length);
return piex::Error::kFail;
}