/** * Ensure this is an ORC file to prevent users from trying to read text * files or RC files as ORC files. * @param in the file being read * @param path the filename for error messages * @param psLen the postscript length * @param buffer the tail of the file * @ */ static void ensureOrcFooter(Stream @in, string path, int psLen, ByteBuffer buffer) { int len = OrcFile.MAGIC.Length; if (psLen < len + 1) { throw new FormatException("Malformed ORC file " + path + ". Invalid postscript length " + psLen); } int offset = buffer.arrayOffset() + buffer.position() + buffer.limit() - 1 - len; byte[] array = buffer.array(); // now look for the magic string at the end of the postscript. if (!Lists.AreEqual(array, offset, OrcFile.MAGIC, len)) { // If it isn't there, this may be the 0.11.0 version of ORC. // Read the first 3 bytes of the file to check for the header byte[] header = new byte[len]; @in.readFully(0, header, 0, len); // if it isn't there, this isn't an ORC file if (!Lists.AreEqual(header, 0, OrcFile.MAGIC, len)) { throw new FormatException("Malformed ORC file " + path + ". Invalid postscript."); } } }