diff options
author | Neil Fuller <nfuller@google.com> | 2020-07-22 09:50:10 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-07-22 09:50:10 +0000 |
commit | 59b93bdba792e0a6363022dbda0c796f3da9e6f7 (patch) | |
tree | 3b9a5be15268fe2dfb0c9139555523d8ad0916ac | |
parent | 2b7cb0c44b28d29a969f0d69ef0d88c9d135a8e0 (diff) | |
parent | b67b5a3eea4cea71a28e478addf19393cd039b4e (diff) | |
download | icu-59b93bdba792e0a6363022dbda0c796f3da9e6f7.tar.gz |
Merge "Remove redundant zone.tab section from tzdata"
-rw-r--r-- | android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/ZoneInfoDb.java | 33 | ||||
-rw-r--r-- | android_icu4j/testing/src/com/android/i18n/test/timezone/ZoneInfoDbTest.java | 29 |
2 files changed, 4 insertions, 58 deletions
diff --git a/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/ZoneInfoDb.java b/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/ZoneInfoDb.java index 658f62cc6..cac846957 100644 --- a/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/ZoneInfoDb.java +++ b/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/ZoneInfoDb.java @@ -75,7 +75,6 @@ public final class ZoneInfoDb implements AutoCloseable { private MemoryMappedFile mappedFile; private String version; - private String zoneTab; /** * The 'ids' array contains time zone ids sorted alphabetically, for binary searching. @@ -174,7 +173,6 @@ public final class ZoneInfoDb implements AutoCloseable { private void populateFallback() { version = "missing"; - zoneTab = "# Emergency fallback data.\n"; ids = new String[] { "GMT" }; byteOffsets = rawUtcOffsetsCache = new int[1]; } @@ -207,7 +205,6 @@ public final class ZoneInfoDb implements AutoCloseable { // byte[12] tzdata_version -- "tzdata2012f\0" // int index_offset // int data_offset - // int zonetab_offset // int final_offset BufferIterator it = mappedFile.bigEndianIterator(); @@ -222,42 +219,23 @@ public final class ZoneInfoDb implements AutoCloseable { final int fileSize = mappedFile.size(); int index_offset = it.readInt(); - validateOffset(index_offset, fileSize); int data_offset = it.readInt(); - validateOffset(data_offset, fileSize); - int zonetab_offset = it.readInt(); - validateOffset(zonetab_offset, fileSize); int final_offset = it.readInt(); if (index_offset >= data_offset - || data_offset >= zonetab_offset - || zonetab_offset >= final_offset + || data_offset >= final_offset || final_offset > fileSize) { throw new IOException("Invalid offset: index_offset=" + index_offset - + ", data_offset=" + data_offset + ", zonetab_offset=" + zonetab_offset - + ", final_offset=" + final_offset + ", fileSize=" + fileSize); + + ", data_offset=" + data_offset + ", final_offset=" + final_offset + + ", fileSize=" + fileSize); } readIndex(it, index_offset, data_offset); - readZoneTab(it, zonetab_offset, final_offset - zonetab_offset); } catch (IndexOutOfBoundsException e) { throw new IOException("Invalid read from data file", e); } } - private static void validateOffset(int offset, int size) throws IOException { - if (offset < 0 || offset >= size) { - throw new IOException("Invalid offset=" + offset + ", size=" + size); - } - } - - private void readZoneTab(BufferIterator it, int zoneTabOffset, int zoneTabSize) { - byte[] bytes = new byte[zoneTabSize]; - it.seek(zoneTabOffset); - it.readByteArray(bytes, 0, bytes.length); - zoneTab = new String(bytes, 0, bytes.length, StandardCharsets.US_ASCII); - } - private void readIndex(BufferIterator it, int indexOffset, int dataOffset) throws IOException { it.seek(indexOffset); @@ -374,11 +352,6 @@ public final class ZoneInfoDb implements AutoCloseable { return version; } - public String getZoneTab() { - checkNotClosed(); - return zoneTab; - } - @libcore.api.CorePlatformApi @libcore.api.IntraCoreApi public ZoneInfoData makeZoneInfoData(String id) { diff --git a/android_icu4j/testing/src/com/android/i18n/test/timezone/ZoneInfoDbTest.java b/android_icu4j/testing/src/com/android/i18n/test/timezone/ZoneInfoDbTest.java index 8657dcf7a..42806cfc8 100644 --- a/android_icu4j/testing/src/com/android/i18n/test/timezone/ZoneInfoDbTest.java +++ b/android_icu4j/testing/src/com/android/i18n/test/timezone/ZoneInfoDbTest.java @@ -128,19 +128,6 @@ public class ZoneInfoDbTest extends junit.framework.TestCase { checkInvalidDataDetected(data); } - public void testLoadTzData_zoneTabOffsetOutsideFile() throws Exception { - ZoneInfoTestHelper.TzDataBuilder builder = - new ZoneInfoTestHelper.TzDataBuilder() - .initializeToValid(); - - builder.setZoneTabOffsetOverride(3000); // This is invalid if it is outside of the file. - - byte[] data = builder.build(); - // The zoneTab offset must be outside of the file for this test to be valid. - assertTrue(3000 > data.length); - checkInvalidDataDetected(data); - } - public void testLoadTzData_finalOffsetOutsideFile() throws Exception { ZoneInfoTestHelper.TzDataBuilder builder = new ZoneInfoTestHelper.TzDataBuilder() @@ -163,7 +150,7 @@ public class ZoneInfoDbTest extends junit.framework.TestCase { builder.setIndexOffsetOverride(indexOffset); int dataOffset = indexOffset + ZoneInfoDb.SIZEOF_INDEX_ENTRY - 1; builder.setDataOffsetOverride(dataOffset); - builder.setZoneTabOffsetOverride(dataOffset + 40); + builder.setFinalOffsetOverride(dataOffset + 40); byte[] data = builder.build(); // The zoneTab offset must be outside of the file for this test to be valid. @@ -254,20 +241,6 @@ public class ZoneInfoDbTest extends junit.framework.TestCase { } } - public void testGetZoneTab() throws Exception { - String zoneTab = "This is my zone.tab"; - ZoneInfoTestHelper.TzDataBuilder builder = - new ZoneInfoTestHelper.TzDataBuilder() - .initializeToValid() - .setZoneTab(zoneTab); - - byte[] data = builder.build(); - File testFile = makeTemporaryFile(data); - - ZoneInfoDb zoneInfoDb = ZoneInfoDb.loadTzData(testFile.getPath()); - assertEquals(zoneTab, zoneInfoDb.getZoneTab()); - } - private static File makeCorruptFile() throws Exception { return makeTemporaryFile("invalid content".getBytes()); } |