チケット #15596

TAR展開でエラー(bad header)

登録: 2009-03-18 09:58 最終更新: 2009-03-18 21:51

報告者:
(匿名)
担当者:
チケットの種類:
状況:
完了
コンポーネント:
(未割り当て)
マイルストーン:
優先度:
5 - 中
重要度:
7
解決法:
修正済み
ファイル:
なし

詳細

TARファイルを展開しようとすると、以下のエラーになる。

$ arm xvf test.tar
(中略)
armadillo: I/O error - bad header: size=-1            

最初のエントリだけ展開されるが、このファイルが元のデータよりも異常に大きい。

チケットの履歴 (3 件中 3 件表示)

2009-03-18 09:58 更新者: None
  • 新しいチケット "TAR展開でエラー(bad header)" が作成されました
2009-03-18 10:05 更新者: argius
  • 解決法なし から 後で に更新されました
コメント

"#15565 ZipInputStreamでエントリのダンプが上手くいかない"によるデグレード。

但し、元の構造が不適当だったのも問題。

以下は修正パッチ。

Index: src/jp/sourceforge/armadillo/tar/TarInputStream.java
===================================================================
--- src/jp/sourceforge/armadillo/tar/TarInputStream.java	(revision 17)
+++ src/jp/sourceforge/armadillo/tar/TarInputStream.java	(working copy)
@@ -31,6 +31,7 @@
         super(is);
         this.header = new TarHeader(charsetName);
         this.skipSize = 0;
+        frontStream = is;
     }
 
     /**
Index: src/jp/sourceforge/armadillo/io/ArchiveInputStream.java
===================================================================
--- src/jp/sourceforge/armadillo/io/ArchiveInputStream.java	(revision 17)
+++ src/jp/sourceforge/armadillo/io/ArchiveInputStream.java	(working copy)
@@ -37,17 +37,19 @@
      */
     public int read() throws IOException {
         ensureOpen();
-        if (frontStream != null && remaining <= 0) {
+        if (frontStream == null) {
+            return super.read();
+        } else if (remaining <= 0) {
             assert remaining == 0;
             return -1;
-        }
-        InputStream is = (frontStream == null) ? in : frontStream;
-        int read = is.read();
-        if (read == -1) {
-            return -1;
+        } else {
+            int read = frontStream.read();
+            if (read == -1) {
+                return -1;
+            }
+            --remaining;
+            return read;
         }
-        --remaining;
-        return read;
     }
 
     /* (overridden)
@@ -55,16 +57,19 @@
      */
     public int read(byte[] b, int off, int len) throws IOException {
         ensureOpen();
-        if (frontStream != null && remaining <= 0) {
+        if (frontStream == null) {
+            return super.read(b, off, len);
+        } else if (remaining <= 0) {
             assert remaining == 0;
             return -1;
-        }
-        InputStream is = (frontStream == null) ? in : frontStream;
-        int readLength = is.read(b, off, (int)Math.min(len, remaining));
-        if (readLength >= 0) {
-            remaining -= readLength;
+        } else {
+            int readLength = frontStream.read(b, off, (int)Math.min(len, remaining));
+            if (readLength >= 0) {
+                remaining -= readLength;
+            }
+            assert readLength != 0;
+            return readLength;
         }
-        return readLength;
     }
 
     /* (overridden)
@@ -72,17 +77,18 @@
      */
     public long skip(long n) throws IOException {
         ensureOpen();
-        if (frontStream != null && remaining <= 0) {
+        if (frontStream == null) {
+            return super.skip(n);
+        } else if (remaining <= 0) {
             assert remaining == 0;
             return -1;
+        } else {
+            long skipped = frontStream.skip(n);
+            if (skipped > 0) {
+                remaining -= skipped;
+            }
+            return skipped;
         }
-        long skipped;
-        InputStream is = (frontStream == null) ? in : frontStream;
-        skipped = is.skip(n);
-        if (skipped > 0) {
-            remaining -= skipped;
-        }
-        return skipped;
     }
 
     /* (overridden)
2009-03-18 21:51 更新者: argius
  • 解決法後で から 修正済み に更新されました
  • 状況オープン から 完了 に更新されました
  • チケット完了時刻2009-03-18 21:51 に更新されました
コメント

パッチ完了。

添付ファイルリスト

添付ファイルはありません

編集

ログインしていません。ログインしていない状態では、コメントに記載者の記録が残りません。 » ログインする