You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2009/03/28 17:48:51 UTC
svn commit: r759508 -
/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
Author: sebb
Date: Sat Mar 28 16:48:51 2009
New Revision: 759508
URL: http://svn.apache.org/viewvc?rev=759508&view=rev
Log:
Update match()
- add detection of binary format
- tighten detection of ascii formats; ensure last byte is correct
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java?rev=759508&r1=759507&r2=759508&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java Sat Mar 28 16:48:51 2009
@@ -425,12 +425,34 @@
return getNextCPIOEntry();
}
+ /**
+ * Checks if the signature matches one of the following magic values:
+ *
+ * Strings:
+ *
+ * "070701" - MAGIC_NEW
+ * "070702" - MAGIC_NEW_CRC
+ * "070707" - MAGIC_OLD_ASCII
+ *
+ * Octal Binary value:
+ *
+ * 070707 - MAGIC_OLD_BINARY (held as a short) = 0x71C7 or 0xC771
+ */
public static boolean matches(byte[] signature, int length) {
- // 3037 3037 30
-
- if (length < 5) {
+ if (length < 6) {
return false;
}
+
+ // Check binary values
+ if (signature[0] == 0x71 && signature[1] == 0xc7) {
+ return true;
+ }
+ if (signature[1] == 0x71 && signature[2] == 0xc7) {
+ return true;
+ }
+
+ // Check Ascii (String) values
+ // 3037 3037 30nn
if (signature[0] != 0x30) {
return false;
}
@@ -446,7 +468,17 @@
if (signature[4] != 0x30) {
return false;
}
+ // Check last byte
+ if (signature[5] == 0x31) {
+ return true;
+ }
+ if (signature[5] == 0x32) {
+ return true;
+ }
+ if (signature[5] == 0x37) {
+ return true;
+ }
- return true;
+ return false;
}
}