summaryrefslogtreecommitdiff
path: root/libs/androidfw/BigBuffer.cpp
diff options
context:
space:
mode:
author Yurii Zubrytskyi <zyy@google.com> 2024-08-09 10:47:08 -0700
committer Yurii Zubrytskyi <zyy@google.com> 2024-08-09 10:47:08 -0700
commit707263e428bf711a19e55a48581c3d79c5a6f62f (patch)
tree168606d772f77a183df2cad5df1ade4bbb758c9f /libs/androidfw/BigBuffer.cpp
parentac310d16b1f8f808555f7ce3633b884bb92c0b36 (diff)
[res] Zero big buffer memory on backing up
When a memory chunk gets returned into BigBuffer, it may have some data written already. BigBuffer is supposed to give out zeroed memory, so BackUp() needs to zero it as well Bug: 336758568 Bug: 342579978 Test: unit test + bundletool on the attached aab Flag: EXEMPT bugfix Change-Id: I8ecd60e84dbe16570a92d82370d1633af72599c8
Diffstat (limited to 'libs/androidfw/BigBuffer.cpp')
-rw-r--r--libs/androidfw/BigBuffer.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/libs/androidfw/BigBuffer.cpp b/libs/androidfw/BigBuffer.cpp
index bedfc49a1b0d..43b56c32fb79 100644
--- a/libs/androidfw/BigBuffer.cpp
+++ b/libs/androidfw/BigBuffer.cpp
@@ -17,8 +17,8 @@
#include <androidfw/BigBuffer.h>
#include <algorithm>
+#include <iterator>
#include <memory>
-#include <vector>
#include "android-base/logging.h"
@@ -78,10 +78,27 @@ void* BigBuffer::NextBlock(size_t* out_size) {
std::string BigBuffer::to_string() const {
std::string result;
+ result.reserve(size_);
for (const Block& block : blocks_) {
result.append(block.buffer.get(), block.buffer.get() + block.size);
}
return result;
}
+void BigBuffer::AppendBuffer(BigBuffer&& buffer) {
+ std::move(buffer.blocks_.begin(), buffer.blocks_.end(), std::back_inserter(blocks_));
+ size_ += buffer.size_;
+ buffer.blocks_.clear();
+ buffer.size_ = 0;
+}
+
+void BigBuffer::BackUp(size_t count) {
+ Block& block = blocks_.back();
+ block.size -= count;
+ size_ -= count;
+ // BigBuffer is supposed to always give zeroed memory, but backing up usually means
+ // something has been already written into the block. Erase it.
+ std::fill_n(block.buffer.get() + block.size, count, 0);
+}
+
} // namespace android