@@ -702,28 +702,43 @@ func streamPathToBuild(repo git.Repository, in io.Reader, out io.Writer, client
702702}
703703
704704func isArchive (r * bufio.Reader ) bool {
705- data , err := r .Peek (280 )
706- if err != nil {
705+ archivesMagicNumbers := []struct {
706+ numbers []byte
707+ offset int
708+ }{ //https://en.wikipedia.org/wiki/List_of_file_signatures
709+ { // unified tar
710+ numbers : []byte {0x75 , 0x73 , 0x74 , 0x61 , 0x72 },
711+ offset : 0x101 ,
712+ },
713+ { //zip
714+ numbers : []byte {0x50 , 0x4B , 0x03 , 0x04 },
715+ },
716+ { // tar.z
717+ numbers : []byte {0x1F , 0x9D },
718+ },
719+ { // tar.z
720+ numbers : []byte {0x1F , 0xA0 },
721+ },
722+ { // bz2
723+ numbers : []byte {0x42 , 0x5A , 0x68 },
724+ },
725+ { // gzip
726+ numbers : []byte {0x1F , 0x8B },
727+ },
728+ }
729+ maxOffset := archivesMagicNumbers [0 ].offset //unified tar
730+ data , err := r .Peek (maxOffset + len (archivesMagicNumbers [0 ].numbers ))
731+ if err != nil && err != io .EOF {
707732 return false
708733 }
709- for _ , b := range [][]byte {
710- {0x50 , 0x4B , 0x03 , 0x04 }, // zip
711- {0x1F , 0x9D }, // tar.z
712- {0x1F , 0xA0 }, // tar.z
713- {0x42 , 0x5A , 0x68 }, // bz2
714- {0x1F , 0x8B , 0x08 }, // gzip
715- } {
716- if bytes .HasPrefix (data , b ) {
734+
735+ for _ , magic := range archivesMagicNumbers {
736+ if len (data ) >= magic .offset + len (magic .numbers ) &&
737+ bytes .Equal (data [magic .offset :magic .offset + len (magic .numbers )], magic .numbers ) {
717738 return true
718739 }
719740 }
720- switch {
721- // Unified TAR files have this magic number
722- case len (data ) > 257 + 5 && bytes .Equal (data [257 :257 + 5 ], []byte {0x75 , 0x73 , 0x74 , 0x61 , 0x72 }):
723- return true
724- default :
725- return false
726- }
741+ return false
727742}
728743
729744// RunStartBuildWebHook tries to trigger the provided webhook. It will attempt to utilize the current client
0 commit comments