You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "yakovsh (via GitHub)" <gi...@apache.org> on 2023/11/15 17:46:16 UTC

[PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

yakovsh opened a new pull request, #442:
URL: https://github.com/apache/commons-compress/pull/442

   This PR adds a few fixes and unit tests for dump file parsing, related to fuzzing work in COMPRESS-632.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #442:
URL: https://github.com/apache/commons-compress/pull/442


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #442:
URL: https://github.com/apache/commons-compress/pull/442#discussion_r1402651501


##########
src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveConstants.java:
##########
@@ -26,7 +26,7 @@ public final class DumpArchiveConstants {
      * The type of compression.
      */
     public enum COMPRESSION_TYPE {
-        ZLIB(0), BZLIB(1), LZO(2);
+        UNKNOWN(-1), ZLIB(0), BZLIB(1), LZO(2);

Review Comment:
   Is this required? Does it avoid an NPE? I do not see it used outside of this enum.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "yakovsh (via GitHub)" <gi...@apache.org>.
yakovsh commented on code in PR #442:
URL: https://github.com/apache/commons-compress/pull/442#discussion_r1406841978


##########
src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveConstants.java:
##########
@@ -26,7 +26,7 @@ public final class DumpArchiveConstants {
      * The type of compression.
      */
     public enum COMPRESSION_TYPE {
-        ZLIB(0), BZLIB(1), LZO(2);
+        UNKNOWN(-1), ZLIB(0), BZLIB(1), LZO(2);

Review Comment:
   This prevents the NPE on line 208 of TapeInputStream:
   https://github.com/apache/commons-compress/blob/master/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java#L208
   
   This is also what the "invalid_compression_type.dump" file is testing



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "yakovsh (via GitHub)" <gi...@apache.org>.
yakovsh commented on PR #442:
URL: https://github.com/apache/commons-compress/pull/442#issuecomment-1813330529

   @garydgregory I re-based from master and fixed issues surfaced by checkstyle


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #442:
URL: https://github.com/apache/commons-compress/pull/442#discussion_r1402647680


##########
src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java:
##########
@@ -294,6 +294,9 @@ public void resetBlockSize(final int recsPerBlock, final boolean isCompressed) t
             throw new IOException("Block with " + recsPerBlock + " records found, must be at least 1");
         }
         blockSize = RECORD_SIZE * recsPerBlock;
+        if (blockSize < 1) {
+            throw new IOException("Block size " + blockSize + " cannot be negative");

Review Comment:
   Either the test or the error message is incorrect. If the test is correct then the error message should say `"Block size cannot be less than or equal to 0: " + blockSize"`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #442:
URL: https://github.com/apache/commons-compress/pull/442#issuecomment-1813047068

   Please hold off creating PRs while I add checkstyle to the build, it will just cause conflicts; -)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #442:
URL: https://github.com/apache/commons-compress/pull/442#discussion_r1401169457


##########
src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java:
##########
@@ -526,7 +526,7 @@ private void readDirectoryEntry(DumpArchiveEntry entry) throws IOException {
 
             final byte[] peekBytes = raw.peek();
 
-            if (!DumpArchiveUtil.verify(peekBytes)) {
+            if (peekBytes == null || !DumpArchiveUtil.verify(peekBytes)) {

Review Comment:
   Why not put this check in `DumpArchiveUtil.verify(byte[])`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "yakovsh (via GitHub)" <gi...@apache.org>.
yakovsh commented on PR #442:
URL: https://github.com/apache/commons-compress/pull/442#issuecomment-1813079201

   Sure, thanks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #442:
URL: https://github.com/apache/commons-compress/pull/442#issuecomment-1820928708

   ## [Codecov](https://app.codecov.io/gh/apache/commons-compress/pull/442?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: `1 lines` in your changes are missing coverage. Please review.
   > Comparison is base [(`fa1b16d`)](https://app.codecov.io/gh/apache/commons-compress/commit/fa1b16d388dd2ac3f6ce47f989a06cfea8900b82?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 80.55% compared to head [(`f7e6955`)](https://app.codecov.io/gh/apache/commons-compress/pull/442?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 80.63%.
   > Report is 1 commits behind head on master.
   
   | [Files](https://app.codecov.io/gh/apache/commons-compress/pull/442?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...ompress/archivers/dump/DumpArchiveInputStream.java](https://app.codecov.io/gh/apache/commons-compress/pull/442?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvY29tcHJlc3MvYXJjaGl2ZXJzL2R1bXAvRHVtcEFyY2hpdmVJbnB1dFN0cmVhbS5qYXZh) | 0.00% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/commons-compress/pull/442?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master     #442      +/-   ##
   ============================================
   + Coverage     80.55%   80.63%   +0.07%     
   - Complexity     6764     6775      +11     
   ============================================
     Files           342      342              
     Lines         24860    24864       +4     
     Branches       4017     4018       +1     
   ============================================
   + Hits          20027    20049      +22     
   + Misses         3298     3285      -13     
   + Partials       1535     1530       -5     
   ```
   
   
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/commons-compress/pull/442?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "yakovsh (via GitHub)" <gi...@apache.org>.
yakovsh commented on code in PR #442:
URL: https://github.com/apache/commons-compress/pull/442#discussion_r1401261090


##########
src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java:
##########
@@ -526,7 +526,7 @@ private void readDirectoryEntry(DumpArchiveEntry entry) throws IOException {
 
             final byte[] peekBytes = raw.peek();
 
-            if (!DumpArchiveUtil.verify(peekBytes)) {
+            if (peekBytes == null || !DumpArchiveUtil.verify(peekBytes)) {

Review Comment:
   It can go as well, and from the code, it looks like if false is returned, an exception will get thrown anyway, so it makes sense to throw false if buffer is null. I will move it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #442:
URL: https://github.com/apache/commons-compress/pull/442#discussion_r1402651501


##########
src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveConstants.java:
##########
@@ -26,7 +26,7 @@ public final class DumpArchiveConstants {
      * The type of compression.
      */
     public enum COMPRESSION_TYPE {
-        ZLIB(0), BZLIB(1), LZO(2);
+        UNKNOWN(-1), ZLIB(0), BZLIB(1), LZO(2);

Review Comment:
   Is this required? Does it avoid an NPE? I do not see it used outside of this enum,



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "yakovsh (via GitHub)" <gi...@apache.org>.
yakovsh commented on code in PR #442:
URL: https://github.com/apache/commons-compress/pull/442#discussion_r1401261090


##########
src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java:
##########
@@ -526,7 +526,7 @@ private void readDirectoryEntry(DumpArchiveEntry entry) throws IOException {
 
             final byte[] peekBytes = raw.peek();
 
-            if (!DumpArchiveUtil.verify(peekBytes)) {
+            if (peekBytes == null || !DumpArchiveUtil.verify(peekBytes)) {

Review Comment:
   It can go as well, and from the code, it looks like if false is returned, an exception will get thrown anyway, so it makes sense to throw false if buffer is null. I will move it. Thank you for pointing this out.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "yakovsh (via GitHub)" <gi...@apache.org>.
yakovsh commented on code in PR #442:
URL: https://github.com/apache/commons-compress/pull/442#discussion_r1402701318


##########
src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java:
##########
@@ -294,6 +294,9 @@ public void resetBlockSize(final int recsPerBlock, final boolean isCompressed) t
             throw new IOException("Block with " + recsPerBlock + " records found, must be at least 1");
         }
         blockSize = RECORD_SIZE * recsPerBlock;
+        if (blockSize < 1) {
+            throw new IOException("Block size " + blockSize + " cannot be negative");

Review Comment:
   I will fix this, zeros should be invalid as well



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] COMPRESS-632: Fixes for dump file parsing [commons-compress]

Posted by "yakovsh (via GitHub)" <gi...@apache.org>.
yakovsh commented on PR #442:
URL: https://github.com/apache/commons-compress/pull/442#issuecomment-1830050151

   Thank you!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org