Refactor DataBegin() and DataEnd() calculation in DexFile.

In this context, the data range is defined as the memory region
that most of the dex offsets are relative to. It is same as the
whole dex file for standard dex, but special for compact dex.

Push the calculation of this memory range into DexFile internals,
since it will different for multidex in the future (where it will
be the memory range of the whole mulitdex container).

Bug: 266950186
Test: test.py -b --host --all-cdex_level --64
Change-Id: I1e4ad9af975fd15c24c1d89a5fc51c63ea562091
diff --git a/libdexfile/dex/dex_file_loader.cc b/libdexfile/dex/dex_file_loader.cc
index 95e456e..5bf350c 100644
--- a/libdexfile/dex/dex_file_loader.cc
+++ b/libdexfile/dex/dex_file_loader.cc
@@ -354,37 +354,16 @@
   CHECK(container != nullptr);
   const uint8_t* base = container->Begin();
   size_t size = container->Size();
-  const uint8_t* data_base = container->DataBegin();
-  size_t data_size = container->DataEnd() - container->DataBegin();
   if (error_code != nullptr) {
     *error_code = DexFileLoaderErrorCode::kDexFileError;
   }
   std::unique_ptr<DexFile> dex_file;
   if (size >= sizeof(StandardDexFile::Header) && StandardDexFile::IsMagicValid(base)) {
-    if (data_size != 0) {
-      CHECK_EQ(base, data_base) << "Unsupported for standard dex";
-    }
     dex_file.reset(new StandardDexFile(
         base, size, location, location_checksum, oat_dex_file, std::move(container)));
   } else if (size >= sizeof(CompactDexFile::Header) && CompactDexFile::IsMagicValid(base)) {
-    if (data_base == nullptr) {
-      // TODO: Is there a clean way to support both an explicit data section and reading the one
-      // from the header.
-      CHECK_EQ(data_size, 0u);
-      const CompactDexFile::Header* const header = CompactDexFile::Header::At(base);
-      data_base = base + header->data_off_;
-      data_size = header->data_size_;
-    }
-    dex_file.reset(new CompactDexFile(base,
-                                      size,
-                                      data_base,
-                                      data_size,
-                                      location,
-                                      location_checksum,
-                                      oat_dex_file,
-                                      std::move(container)));
-    // Disable verification for CompactDex input.
-    verify = false;
+    dex_file.reset(new CompactDexFile(
+        base, size, location, location_checksum, oat_dex_file, std::move(container)));
   } else {
     *error_msg = "Invalid or truncated dex file";
   }
@@ -397,7 +376,8 @@
     dex_file.reset();
     return nullptr;
   }
-  if (verify) {
+  // NB: Dex verifier does not understand the compact dex format.
+  if (verify && !dex_file->IsCompactDexFile()) {
     ScopedTrace trace(std::string("Verify dex file ") + location);
     if (!dex::Verify(dex_file.get(),
                      dex_file->Begin(),