Snap for 8570526 from 7e486cb657c3ae0f79f77d3d0d93cb7c027919e3 to mainline-networking-release

Change-Id: Iaa461f7c60bb14ca39b44672c0d0ec8b47d681d9
diff --git a/Android.bp b/Android.bp
index ee6dc4f..3541d03 100644
--- a/Android.bp
+++ b/Android.bp
@@ -73,6 +73,7 @@
 
 cc_library_static {
     name: "libbsdiff",
+    recovery_available: true,
     defaults: ["bsdiff_defaults"],
 
     srcs: [
diff --git a/OWNERS b/OWNERS
index ab036c1..b730db9 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,3 +1,5 @@
 deymo@google.com
 senj@google.com
 xunchang@google.com
+zhangkelvin@google.com
+
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 598f4c9..570788d 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -3,5 +3,10 @@
     {
       "name": "bsdiff_unittest"
     }
+  ],
+  "hwasan-postsubmit": [
+    {
+      "name": "bsdiff_unittest"
+    }
   ]
 }
diff --git a/bspatch.cc b/bspatch.cc
index d7f1710..e95b9a2 100644
--- a/bspatch.cc
+++ b/bspatch.cc
@@ -33,8 +33,8 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <inttypes.h>
-#include <stdio.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
diff --git a/compressor_interface.h b/include/bsdiff/compressor_interface.h
similarity index 100%
rename from compressor_interface.h
rename to include/bsdiff/compressor_interface.h
diff --git a/include/bsdiff/control_entry.h b/include/bsdiff/control_entry.h
index 2c849f6..3d2d96c 100644
--- a/include/bsdiff/control_entry.h
+++ b/include/bsdiff/control_entry.h
@@ -8,23 +8,24 @@
 #include <stdint.h>
 
 struct ControlEntry {
-  ControlEntry(uint64_t diff_size,
-               uint64_t extra_size,
-               int64_t offset_increment)
+  constexpr ControlEntry(uint64_t diff_size,
+                         uint64_t extra_size,
+                         int64_t offset_increment)
       : diff_size(diff_size),
         extra_size(extra_size),
         offset_increment(offset_increment) {}
+  constexpr ControlEntry() = default;
 
   // The number of bytes to copy from the source and diff stream.
-  uint64_t diff_size;
+  uint64_t diff_size{0};
 
   // The number of bytes to copy from the extra stream.
-  uint64_t extra_size;
+  uint64_t extra_size{0};
 
   // The value to add to the source pointer after patching from the diff stream.
-  int64_t offset_increment;
+  int64_t offset_increment{0};
 
-  bool operator==(const ControlEntry& o) const {
+  [[nodiscard]] bool operator==(const ControlEntry& o) const {
     return diff_size == o.diff_size && extra_size == o.extra_size &&
            offset_increment == o.offset_increment;
   }
diff --git a/decompressor_interface.h b/include/bsdiff/decompressor_interface.h
similarity index 100%
rename from decompressor_interface.h
rename to include/bsdiff/decompressor_interface.h
diff --git a/file.h b/include/bsdiff/file.h
similarity index 100%
rename from file.h
rename to include/bsdiff/file.h
diff --git a/memory_file.h b/include/bsdiff/memory_file.h
similarity index 100%
rename from memory_file.h
rename to include/bsdiff/memory_file.h
diff --git a/patch_reader.h b/include/bsdiff/patch_reader.h
similarity index 100%
rename from patch_reader.h
rename to include/bsdiff/patch_reader.h
diff --git a/patch_writer.h b/include/bsdiff/patch_writer.h
similarity index 94%
rename from patch_writer.h
rename to include/bsdiff/patch_writer.h
index 8ad4cde..6d2bcf5 100644
--- a/patch_writer.h
+++ b/include/bsdiff/patch_writer.h
@@ -14,6 +14,15 @@
 
 namespace bsdiff {
 
+
+constexpr void EncodeInt64(int64_t x, uint8_t* buf) {
+  uint64_t y = x < 0 ? (1ULL << 63ULL) - x : x;
+  for (int i = 0; i < 8; ++i) {
+    buf[i] = y & 0xff;
+    y /= 256;
+  }
+}
+
 // A PatchWriterInterface class with three compressors and a 32-byte header.
 class BsdiffPatchWriter : public PatchWriterInterface {
  public:
diff --git a/patch_reader.cc b/patch_reader.cc
index e863b9a..6d317f3 100644
--- a/patch_reader.cc
+++ b/patch_reader.cc
@@ -32,7 +32,7 @@
   // extra block; seek forwards in oldfile by z bytes".
 
   if (patch_size < 32) {
-    LOG(ERROR) << "Too small to be a bspatch.";
+    LOG(ERROR) << "Too small to be a bspatch. " << patch_size;
     return false;
   }
   // Check for appropriate magic.
diff --git a/patch_writer.cc b/patch_writer.cc
index 52982e0..b7d9b08 100644
--- a/patch_writer.cc
+++ b/patch_writer.cc
@@ -15,13 +15,6 @@
 
 namespace {
 
-void EncodeInt64(int64_t x, uint8_t* buf) {
-  uint64_t y = x < 0 ? (1ULL << 63ULL) - x : x;
-  for (int i = 0; i < 8; ++i) {
-    buf[i] = y & 0xff;
-    y /= 256;
-  }
-}
 
 }  // namespace
 
diff --git a/suffix_array_index.cc b/suffix_array_index.cc
index b02655c..710249c 100644
--- a/suffix_array_index.cc
+++ b/suffix_array_index.cc
@@ -4,6 +4,7 @@
 
 #include "bsdiff/suffix_array_index.h"
 
+#include <algorithm>
 #include <limits>
 #include <vector>