소스 검색

express: Fix reading zip file with comment at the end

rdb 5 년 전
부모
커밋
c52ea9a8df
1개의 변경된 파일10개의 추가작업 그리고 1개의 파일을 삭제
  1. 10 1
      panda/src/express/zipArchive.cxx

+ 10 - 1
panda/src/express/zipArchive.cxx

@@ -1222,11 +1222,14 @@ read_index() {
   // Seek backwards until we have found the the end-of-directory record.
   StreamReader reader(read, false);
   while (comment_length <= 0xffff && fpos >= 20) {
+    //nassertr(fpos == read->tellg(), false);
+
     if (reader.get_uint16() == comment_length) {
       // This field references the distance to the end of the .zip file, so it
       // could be the comment length field at the end of the record.  Skip to the
       // beginning of the record to see if the signature matches.
       read->seekg(-22, std::ios::cur);
+
       if (reader.get_uint32() == 0x06054b50) {
         // Yes, got it.
         eocd_offset = read->tellg() - (std::streamoff)4;
@@ -1242,10 +1245,16 @@ read_index() {
         found = true;
         break;
       }
+
+      // No, skip back to where we were and continue scanning for comments.
+      comment_length += 2;
+      read->seekg(22 - 4 - 4, std::ios::cur);
+      fpos -= 2;
+      continue;
     }
 
     comment_length += 2;
-    read->seekg(-2, std::ios::cur);
+    read->seekg(-4, std::ios::cur);
     fpos -= 2;
   }