diff --git ql/src/java/org/apache/hadoop/hive/ql/io/orc/SerializationUtils.java ql/src/java/org/apache/hadoop/hive/ql/io/orc/SerializationUtils.java index b14fa7b..f6329b1 100644 --- ql/src/java/org/apache/hadoop/hive/ql/io/orc/SerializationUtils.java +++ ql/src/java/org/apache/hadoop/hive/ql/io/orc/SerializationUtils.java @@ -73,8 +73,13 @@ long readVslong(InputStream in) throws IOException { } float readFloat(InputStream in) throws IOException { - int ser = in.read() | (in.read() << 8) | (in.read() << 16) | - (in.read() << 24); + if (4 != in.read(readBuffer, 0, 4)) { + throw new EOFException("Reading float past EOF"); + } + int ser = ((readBuffer[0] & 0xff) << 0) + | ((readBuffer[1] & 0xff) << 8) + | ((readBuffer[2] & 0xff) << 16) + | ((readBuffer[3] & 0xff) << 24); return Float.intBitsToFloat(ser); } diff --git ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestSerializationUtils.java ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestSerializationUtils.java index b3f9cf1..6bba934 100644 --- ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestSerializationUtils.java +++ ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestSerializationUtils.java @@ -50,6 +50,19 @@ public void testDoubles() throws Exception { } @Test + public void testFloats() throws Exception { + double tolerance = 0.0000000000000001; + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + SerializationUtils utils = new SerializationUtils(); + utils.writeFloat(buffer, 1343822337.759f); + assertEquals(1343822337.759f, utils.readFloat(fromBuffer(buffer)), tolerance); + buffer = new ByteArrayOutputStream(); + utils.writeFloat(buffer, 0.8f); + float got = utils.readFloat(fromBuffer(buffer)); + assertEquals(0.8f, got, tolerance); + } + + @Test public void testBigIntegers() throws Exception { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); SerializationUtils.writeBigInteger(buffer, BigInteger.valueOf(0));