You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by om...@apache.org on 2016/10/02 15:34:27 UTC
orc git commit: ORC-103: Make ORC Reader resilient to 0 length files
(prasanthj via omalley)
Repository: orc
Updated Branches:
refs/heads/master e899bc83f -> 45b9a7aa5
ORC-103: Make ORC Reader resilient to 0 length files (prasanthj via omalley)
Fixes #61
Signed-off-by: Owen O'Malley <om...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/orc/repo
Commit: http://git-wip-us.apache.org/repos/asf/orc/commit/45b9a7aa
Tree: http://git-wip-us.apache.org/repos/asf/orc/tree/45b9a7aa
Diff: http://git-wip-us.apache.org/repos/asf/orc/diff/45b9a7aa
Branch: refs/heads/master
Commit: 45b9a7aa51b1b9e8d7c80cd1a2c824c8a40280b1
Parents: e899bc8
Author: Prasanth Jayachandran <pr...@apache.org>
Authored: Fri Sep 30 13:31:45 2016 -0700
Committer: Owen O'Malley <om...@apache.org>
Committed: Sun Oct 2 08:32:17 2016 -0700
----------------------------------------------------------------------
.../java/org/apache/orc/impl/ReaderImpl.java | 5 ++
.../src/test/org/apache/orc/TestReader.java | 80 ++++++++++++++++++++
2 files changed, 85 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/orc/blob/45b9a7aa/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
----------------------------------------------------------------------
diff --git a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
index 18aaf61..039365c 100644
--- a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
@@ -495,6 +495,11 @@ public class ReaderImpl implements Reader {
size = maxFileLength;
modificationTime = -1;
}
+ // Anything lesser than MAGIC header cannot be valid (valid ORC file is actually around 45 bytes, this is
+ // more conservative)
+ if (size <= OrcFile.MAGIC.length()) {
+ throw new FileFormatException("Not a valid ORC file");
+ }
fileTailBuilder.setFileLength(size);
//read last bytes into buffer to get PostScript
http://git-wip-us.apache.org/repos/asf/orc/blob/45b9a7aa/java/core/src/test/org/apache/orc/TestReader.java
----------------------------------------------------------------------
diff --git a/java/core/src/test/org/apache/orc/TestReader.java b/java/core/src/test/org/apache/orc/TestReader.java
new file mode 100644
index 0000000..fc4ebdc
--- /dev/null
+++ b/java/core/src/test/org/apache/orc/TestReader.java
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.orc;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestReader {
+ Path workDir = new Path(System.getProperty("test.tmp.dir",
+ "target" + File.separator + "test" + File.separator + "tmp"));
+ Configuration conf;
+ FileSystem fs;
+ Path testFilePath;
+
+ @Rule
+ public TestName testCaseName = new TestName();
+
+ @Before
+ public void openFileSystem() throws Exception {
+ conf = new Configuration();
+ fs = FileSystem.getLocal(conf);
+ testFilePath = new Path(workDir, TestReader.class.getSimpleName() + "." +
+ testCaseName.getMethodName() + ".orc");
+ fs.delete(testFilePath, false);
+ }
+
+ @Test(expected=FileFormatException.class)
+ public void testReadZeroLengthFile() throws Exception {
+ FSDataOutputStream fout = fs.create(testFilePath);
+ fout.close();
+ assertEquals(0, fs.getFileStatus(testFilePath).getLen());
+ OrcFile.createReader(testFilePath,
+ OrcFile.readerOptions(conf).filesystem(fs));
+ }
+
+ @Test(expected=FileFormatException.class)
+ public void testReadFileLengthLessThanMagic() throws Exception {
+ FSDataOutputStream fout = fs.create(testFilePath);
+ fout.writeBoolean(true);
+ fout.close();
+ assertEquals(1, fs.getFileStatus(testFilePath).getLen());
+ OrcFile.createReader(testFilePath,
+ OrcFile.readerOptions(conf).filesystem(fs));
+ }
+
+ @Test(expected=FileFormatException.class)
+ public void testReadFileInvalidHeader() throws Exception {
+ FSDataOutputStream fout = fs.create(testFilePath);
+ fout.writeLong(1);
+ fout.close();
+ assertEquals(8, fs.getFileStatus(testFilePath).getLen());
+ OrcFile.createReader(testFilePath,
+ OrcFile.readerOptions(conf).filesystem(fs));
+ }
+}