diff options
author | 2017-09-27 15:22:21 -0700 | |
---|---|---|
committer | 2017-10-03 15:41:14 -0700 | |
commit | dbbe33b95336efa74e8bb4ebcf6cba50919aa247 (patch) | |
tree | 737276cbe7f1a04572eaa58ca290f19bf54d22f1 /libs/ui/GraphicBufferMapper.cpp | |
parent | a932e64d699eee455e044da38f6a4109774222ea (diff) |
libui: harden GraphicBufferMapper::importBuffer
Add support for validateBufferSize and getTransportSize from IMapper
2.1. Update GraphicBufferMapper::importBuffer to validate buffer
size, and update GraphicBuffer::flatten to use the handle transport
size.
This fixes two issues with GraphicBuffer. Pointers returned by
lock/lockYCbCr can now be accessed without potential OOB. flatten
no longer includes process-local runtime data.
Bug: 62535446
Bug: 62084097
Bug: 32587089
Test: manual
Change-Id: Ice13af26b84f25e43089637e9d67e3ad820e22ed
Diffstat (limited to 'libs/ui/GraphicBufferMapper.cpp')
-rw-r--r-- | libs/ui/GraphicBufferMapper.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index 163432821f..672dc361a1 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -52,17 +52,42 @@ GraphicBufferMapper::GraphicBufferMapper() } status_t GraphicBufferMapper::importBuffer(buffer_handle_t rawHandle, + uint32_t width, uint32_t height, uint32_t layerCount, + PixelFormat format, uint64_t usage, uint32_t stride, buffer_handle_t* outHandle) { ATRACE_CALL(); + buffer_handle_t bufferHandle; Gralloc2::Error error = mMapper->importBuffer( - hardware::hidl_handle(rawHandle), outHandle); + hardware::hidl_handle(rawHandle), &bufferHandle); + if (error != Gralloc2::Error::NONE) { + ALOGW("importBuffer(%p) failed: %d", rawHandle, error); + return static_cast<status_t>(error); + } + + Gralloc2::IMapper::BufferDescriptorInfo info = {}; + info.width = width; + info.height = height; + info.layerCount = layerCount; + info.format = static_cast<Gralloc2::PixelFormat>(format); + info.usage = usage; + error = mMapper->validateBufferSize(bufferHandle, info, stride); + if (error != Gralloc2::Error::NONE) { + ALOGE("validateBufferSize(%p) failed: %d", rawHandle, error); + freeBuffer(bufferHandle); + return static_cast<status_t>(error); + } - ALOGW_IF(error != Gralloc2::Error::NONE, "importBuffer(%p) failed: %d", - rawHandle, error); + *outHandle = bufferHandle; - return static_cast<status_t>(error); + return NO_ERROR; +} + +void GraphicBufferMapper::getTransportSize(buffer_handle_t handle, + uint32_t* outTransportNumFds, uint32_t* outTransportNumInts) +{ + mMapper->getTransportSize(handle, outTransportNumFds, outTransportNumInts); } status_t GraphicBufferMapper::freeBuffer(buffer_handle_t handle) |