summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-10-10 23:43:35 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-10-10 23:43:35 +0000
commit0f65d6e38ab531af1a090d01fc7c4c04a46484bc (patch)
tree81e5ec8ee1c19b491771fb60bf6262d1872d9f7f
parent0564edd993398232c9524f00bc14c7229c6b2523 (diff)
parent46cba442d25e16cce4d5f009f4700a88d53636b1 (diff)
downloadandroid_hardware_interfaces-0f65d6e38ab531af1a090d01fc7c4c04a46484bc.tar.gz
android_hardware_interfaces-0f65d6e38ab531af1a090d01fc7c4c04a46484bc.tar.bz2
android_hardware_interfaces-0f65d6e38ab531af1a090d01fc7c4c04a46484bc.zip
Merge "Legacy wrapper: Use arbitrary limit on buffer size" into oc-mr1-dev
-rw-r--r--audio/2.0/default/Stream.h7
-rw-r--r--audio/2.0/default/StreamIn.cpp12
-rw-r--r--audio/2.0/default/StreamOut.cpp11
3 files changed, 14 insertions, 16 deletions
diff --git a/audio/2.0/default/Stream.h b/audio/2.0/default/Stream.h
index 82f05a77b..e29af5318 100644
--- a/audio/2.0/default/Stream.h
+++ b/audio/2.0/default/Stream.h
@@ -49,6 +49,13 @@ using ::android::sp;
struct Stream : public IStream, public ParametersUtil {
explicit Stream(audio_stream_t* stream);
+ /** 1GiB is the maximum buffer size the HAL client is allowed to request.
+ * This value has been chosen to be under SIZE_MAX and still big enough
+ * for all audio use case.
+ * Keep private for 2.0, put in .hal in 2.1
+ */
+ static constexpr uint32_t MAX_BUFFER_SIZE = 2 << 30 /* == 1GiB */;
+
// Methods from ::android::hardware::audio::V2_0::IStream follow.
Return<uint64_t> getFrameSize() override;
Return<uint64_t> getFrameCount() override;
diff --git a/audio/2.0/default/StreamIn.cpp b/audio/2.0/default/StreamIn.cpp
index b81cbb924..9c933a920 100644
--- a/audio/2.0/default/StreamIn.cpp
+++ b/audio/2.0/default/StreamIn.cpp
@@ -347,14 +347,10 @@ Return<void> StreamIn::prepareForReading(uint32_t frameSize,
sendError(Result::INVALID_ARGUMENTS);
return Void();
}
- // A message queue asserts if it can not handle the requested buffer,
- // thus the client has to guess the maximum size it can handle
- // Choose an arbitrary margin for the overhead of a message queue
- size_t metadataOverhead = 100000;
- if (frameSize >
- (std::numeric_limits<size_t>::max() - metadataOverhead) / framesCount) {
- ALOGE("Buffer too big: %u*%u bytes can not fit in a message queue",
- frameSize, framesCount);
+
+ if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) {
+ ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount,
+ Stream::MAX_BUFFER_SIZE);
sendError(Result::INVALID_ARGUMENTS);
return Void();
}
diff --git a/audio/2.0/default/StreamOut.cpp b/audio/2.0/default/StreamOut.cpp
index 290d0b103..22dcd0c99 100644
--- a/audio/2.0/default/StreamOut.cpp
+++ b/audio/2.0/default/StreamOut.cpp
@@ -323,14 +323,9 @@ Return<void> StreamOut::prepareForWriting(uint32_t frameSize,
sendError(Result::INVALID_ARGUMENTS);
return Void();
}
- // A message queue asserts if it can not handle the requested buffer,
- // thus the client has to guess the maximum size it can handle
- size_t metadataOverhead =
- 100000; // Arbitrary margin for the overhead of a message queue
- if (frameSize >
- (std::numeric_limits<size_t>::max() - metadataOverhead) / framesCount) {
- ALOGE("Buffer too big: %u*%u bytes can not fit in a message queue",
- frameSize, framesCount);
+ if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) {
+ ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount,
+ Stream::MAX_BUFFER_SIZE);
sendError(Result::INVALID_ARGUMENTS);
return Void();
}