From 01bdb180a3f8db32f83a8820b738c128ebfa9786 Mon Sep 17 00:00:00 2001 From: Lynnesbian Date: Mon, 21 Nov 2022 11:51:45 +1000 Subject: [PATCH 1/2] CPIO support --- src/map.rs | 6 ++++++ src/matchers/archive.rs | 14 ++++++++++++++ testdata/sample.cpio | Bin 0 -> 1024 bytes tests/archive.rs | 2 ++ 4 files changed, 22 insertions(+) create mode 100644 testdata/sample.cpio diff --git a/src/map.rs b/src/map.rs index 1d92627..05e16a6 100644 --- a/src/map.rs +++ b/src/map.rs @@ -564,6 +564,12 @@ matcher_map!( "msi", matchers::archive::is_msi ), + ( + MatcherType::Archive, + "application/x-cpio", + "cpio", + matchers::archive::is_cpio + ), // Text ( MatcherType::Text, diff --git a/src/matchers/archive.rs b/src/matchers/archive.rs index 710ab99..3e6c53e 100644 --- a/src/matchers/archive.rs +++ b/src/matchers/archive.rs @@ -216,3 +216,17 @@ pub fn is_msi(buf: &[u8]) -> bool { && buf[6] == 0x1A && buf[7] == 0xE1 } + +/// Returns whether a buffer is a CPIO archive. +pub fn is_cpio(buf: &[u8]) -> bool { + (buf.len() > 1 + && ((buf[0] == 0xC7 && buf[1] == 0x71) // little endian, old format + || (buf[0] == 0x71 && buf[1] == 0xC7))) // big endian, old format + || (buf.len() > 6 + && buf[0] == 0x30 + && buf[1] == 0x37 + && buf[2] == 0x30 + && buf[3] == 0x37 + && buf[4] == 0x30 + && buf[5] == 0x31) // newc format +} diff --git a/testdata/sample.cpio b/testdata/sample.cpio new file mode 100644 index 0000000000000000000000000000000000000000..ea1b8bd6925d3d5ace1f0441557b80d0ac43d4e4 GIT binary patch literal 1024 zcmcgrO^?$s5asM&;rhHyoVME*1c>gohn3h%*;`a0$DXEU<2cw3Y_;OQGftX9IrYRG zJf838r!imf1<&|=eLtJeHXLP{t!7d4>1KJMInUHU+pw_W^vOs41S<>hWL z?}aOE60E7-pyZ8^&!U7Ksf7Xhfihk1!7=g!oY%IF9-d@b!Wj{5I9TV=m9snhP1N+g zDx&^W8lkI1TJw?Z2q+y+l@p#V8ByS+)6L-gVnkI@=|lh;EbZpey{^zYHb4vEK~bD+ zM5!gMTT_6eUYE59tpm?Ur6tt91N->!#Kvgd1 zcvZTxvNcc#F;FuMz<^JjAKJo;tXdTzcoC+lVE1PeB6W;3A{;P@o#H-?ZUo1WukWpPpvJ@OzebW= zK?AjdT59k+f)g?NN-x%Gfm?M$ZMPYs!gz2k&|d`i5`RSe6W7VLdH;4h|B0vV>f!Td MI~tARpZMSM8_=K$xc~qF literal 0 HcmV?d00001 diff --git a/tests/archive.rs b/tests/archive.rs index f2f1e1d..37c8e5a 100644 --- a/tests/archive.rs +++ b/tests/archive.rs @@ -9,3 +9,5 @@ test_format!( ); test_format!(Archive, "application/zstd", "zst", zst, "sample.tar.zst"); + +test_format!(Archive, "application/x-cpio", "cpio", cpio, "sample.cpio"); From 0e6dacb245957569f0aeab713e694be5073ce27a Mon Sep 17 00:00:00 2001 From: Lynnesbian Date: Mon, 21 Nov 2022 14:27:10 +1000 Subject: [PATCH 2/2] add CPIO to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 69d8f7e..ad05b93 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,7 @@ assert_eq!(kind.extension(), "foo"); - **dcm** - `application/dicom` - **zst** - `application/zstd` - **msi** - `application/x-ole-storage` +- **cpio** - `application/x-cpio` #### Book