summaryrefslogtreecommitdiffstats
path: root/libs/androidfw
diff options
context:
space:
mode:
authorChristopher Tate <ctate@google.com>2014-02-21 12:50:21 -0800
committerChristopher Tate <ctate@google.com>2014-02-21 12:58:04 -0800
commitb048c33d5bdaec747195dfedf971d4d9155f5000 (patch)
tree0a69524ee0627aea73c245f83f2d0301882143e3 /libs/androidfw
parent1a405db22a2ade6b745f3e1cf93ba0c54b048d95 (diff)
downloadframeworks_base-b048c33d5bdaec747195dfedf971d4d9155f5000.zip
frameworks_base-b048c33d5bdaec747195dfedf971d4d9155f5000.tar.gz
frameworks_base-b048c33d5bdaec747195dfedf971d4d9155f5000.tar.bz2
Don't assume that we're at start of file at ctor time
BackupDataReader / BackupDataWriter were implicitly assuming that when instantiated, the underlying fd was positioned at start-of-file. If one tried to e.g. open an existing data stream to append further data to it, things might randomly fail (at read time, possibly when consuming the stream later) due to incorrect alignment of the data entities: the appending writer would assume that no padding was needed to achieve correct alignment, and this might easily be false. Now the underlying native reader/writer helpers recognize the true position within the file when constructed, and as a result it's now safe to e.g. construct a BackupDataOutput for an existing file and then append to it. Change-Id: If0484921e687852f923a4b4efabff573a6c16981
Diffstat (limited to 'libs/androidfw')
-rw-r--r--libs/androidfw/BackupData.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/libs/androidfw/BackupData.cpp b/libs/androidfw/BackupData.cpp
index 4e3b522..1a5c55c 100644
--- a/libs/androidfw/BackupData.cpp
+++ b/libs/androidfw/BackupData.cpp
@@ -59,9 +59,10 @@ padding_extra(size_t n)
BackupDataWriter::BackupDataWriter(int fd)
:m_fd(fd),
m_status(NO_ERROR),
- m_pos(0),
m_entityCount(0)
{
+ m_pos = (ssize_t) lseek(fd, 0, SEEK_CUR);
+ if (DEBUG) ALOGI("BackupDataWriter(%d) @ %ld", fd, (long)m_pos);
}
BackupDataWriter::~BackupDataWriter()
@@ -184,10 +185,11 @@ BackupDataReader::BackupDataReader(int fd)
:m_fd(fd),
m_done(false),
m_status(NO_ERROR),
- m_pos(0),
m_entityCount(0)
{
memset(&m_header, 0, sizeof(m_header));
+ m_pos = (ssize_t) lseek(fd, 0, SEEK_CUR);
+ if (DEBUG) ALOGI("BackupDataReader(%d) @ %ld", fd, (long)m_pos);
}
BackupDataReader::~BackupDataReader()