libsnapshot: add compatibility check
Ensure that cow was written by v3 writer for the data_length check to
work. All ops written by v2 writer should go through the decompressor
path if a compressor was used.
Test: cow_api_test
Change-Id: I053d6fdaf29ef7001e68f43b45d5a3ff1a36b1c3
diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/cow_reader.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/cow_reader.cpp
index cacd29d..8412879 100644
--- a/fs_mgr/libsnapshot/libsnapshot_cow/cow_reader.cpp
+++ b/fs_mgr/libsnapshot/libsnapshot_cow/cow_reader.cpp
@@ -685,7 +685,8 @@
} else {
offset = GetCowOpSourceInfoData(*op);
}
- if (!decompressor || op->data_length == header_.block_size) {
+ if (!decompressor ||
+ ((op->data_length == header_.block_size) && (header_.prefix.major_version == 3))) {
CowDataStream stream(this, offset + ignore_bytes, op->data_length - ignore_bytes);
return stream.ReadFully(buffer, buffer_size);
}