You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "tballison (via GitHub)" <gi...@apache.org> on 2023/05/15 14:31:58 UTC
[GitHub] [commons-compress] tballison opened a new pull request, #386: COMPRESS-644 -- do not allow zero by entries when detecting magic-less tar
tballison opened a new pull request, #386:
URL: https://github.com/apache/commons-compress/pull/386
When relying on reading the first record from a tar file and then verifying the checksum as proof that the file is a tar file, require that the record have more than zero bytes.
--
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
[GitHub] [commons-compress] garydgregory commented on a diff in pull request #386: COMPRESS-644 -- do not allow zero by entries when detecting magic-less tar
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #386:
URL: https://github.com/apache/commons-compress/pull/386#discussion_r1194113644
##########
src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java:
##########
@@ -141,4 +145,17 @@ public void testEmptyJarArchive() throws Exception {
public void testEmptyZipArchive() throws Exception {
checkEmptyArchive("zip");
}
+
+ @Test
+ public void ignoreZeroByteEntryInTarDetect_COMPRESS644() throws IOException {
+ try (final InputStream in =
+ new BufferedInputStream(Files.newInputStream(
+ Paths.get("src/test/resources/org/apache/commons" +
+ "/compress/COMPRESS-644/ARW05UP.ICO")))) {
+ ArchiveStreamFactory.detect(in);
+ fail("should have thrown ArchiveException");
+ } catch (ArchiveException e) {
Review Comment:
Use assertThrows().
##########
src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java:
##########
@@ -268,7 +269,16 @@ public static String detect(final InputStream in) throws ArchiveException {
try {
tais = new TarArchiveInputStream(new ByteArrayInputStream(tarHeader));
// COMPRESS-191 - verify the header checksum
- if (tais.getNextTarEntry().isCheckSumOK()) {
+ // COMPRESS-644 - do not allow zero byte file entries
+ TarArchiveEntry tae = tais.getNextTarEntry();
+ //try to find the first non-directory entry within the first 10 entries.
+ int max = 10;
+ int count = 0;
+ while (tae != null && tae.isDirectory() && count++ < max) {
+ tae = tais.getNextTarEntry();
+ }
+ if (tae != null && !tae.isDirectory()
+ && tae.getSize() > 0l && tae.isCheckSumOK()) {
Review Comment:
01?
##########
src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java:
##########
@@ -268,7 +269,16 @@ public static String detect(final InputStream in) throws ArchiveException {
try {
tais = new TarArchiveInputStream(new ByteArrayInputStream(tarHeader));
// COMPRESS-191 - verify the header checksum
- if (tais.getNextTarEntry().isCheckSumOK()) {
+ // COMPRESS-644 - do not allow zero byte file entries
+ TarArchiveEntry tae = tais.getNextTarEntry();
+ //try to find the first non-directory entry within the first 10 entries.
+ int max = 10;
Review Comment:
What makes 10 special? Needs a comment or a better a Javadoc comment for a new constant.
--
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-644 -- do not allow zero by entries when detecting magic-less tar [commons-compress]
Posted by "tballison (via GitHub)" <gi...@apache.org>.
tballison closed pull request #386: COMPRESS-644 -- do not allow zero by entries when detecting magic-less tar
URL: https://github.com/apache/commons-compress/pull/386
--
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
[GitHub] [commons-compress] codecov-commenter commented on pull request #386: COMPRESS-644 -- do not allow zero by entries when detecting magic-less tar
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #386:
URL: https://github.com/apache/commons-compress/pull/386#issuecomment-1548030210
## [Codecov](https://app.codecov.io/gh/apache/commons-compress/pull/386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#386](https://app.codecov.io/gh/apache/commons-compress/pull/386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (ec0b960) into [master](https://app.codecov.io/gh/apache/commons-compress/commit/1223b72b054704c42f1d1e8333008b07307292a4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (1223b72) will **decrease** coverage by `0.02%`.
> The diff coverage is `50.00%`.
```diff
@@ Coverage Diff @@
## master #386 +/- ##
============================================
- Coverage 80.45% 80.44% -0.02%
Complexity 6723 6723
============================================
Files 343 343
Lines 25312 25317 +5
Branches 4107 4109 +2
============================================
+ Hits 20365 20366 +1
- Misses 3366 3367 +1
- Partials 1581 1584 +3
```
| [Impacted Files](https://app.codecov.io/gh/apache/commons-compress/pull/386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...s/compress/compressors/CompressorOutputStream.java](https://app.codecov.io/gh/apache/commons-compress/pull/386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvY29tcHJlc3MvY29tcHJlc3NvcnMvQ29tcHJlc3Nvck91dHB1dFN0cmVhbS5qYXZh) | `100.00% <ø> (ø)` | |
| [...mmons/compress/archivers/ArchiveStreamFactory.java](https://app.codecov.io/gh/apache/commons-compress/pull/386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvY29tcHJlc3MvYXJjaGl2ZXJzL0FyY2hpdmVTdHJlYW1GYWN0b3J5LmphdmE=) | `89.37% <42.85%> (-2.19%)` | :arrow_down: |
| [...mpressors/pack200/InMemoryCachingStreamBridge.java](https://app.codecov.io/gh/apache/commons-compress/pull/386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvY29tcHJlc3MvY29tcHJlc3NvcnMvcGFjazIwMC9Jbk1lbW9yeUNhY2hpbmdTdHJlYW1CcmlkZ2UuamF2YQ==) | `100.00% <100.00%> (ø)` | |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?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
[GitHub] [commons-compress] tballison commented on a diff in pull request #386: COMPRESS-644 -- do not allow zero by entries when detecting magic-less tar
Posted by "tballison (via GitHub)" <gi...@apache.org>.
tballison commented on code in PR #386:
URL: https://github.com/apache/commons-compress/pull/386#discussion_r1194351373
##########
src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java:
##########
@@ -268,7 +269,16 @@ public static String detect(final InputStream in) throws ArchiveException {
try {
tais = new TarArchiveInputStream(new ByteArrayInputStream(tarHeader));
// COMPRESS-191 - verify the header checksum
- if (tais.getNextTarEntry().isCheckSumOK()) {
+ // COMPRESS-644 - do not allow zero byte file entries
+ TarArchiveEntry tae = tais.getNextTarEntry();
+ //try to find the first non-directory entry within the first 10 entries.
+ int max = 10;
Review Comment:
Completely arbitrary. I improved documentation. I'm completely open to the idea of dropping this attempt to iterate through the first x directory entries.
--
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-644 -- do not allow zero by entries when detecting magic-less tar [commons-compress]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #386:
URL: https://github.com/apache/commons-compress/pull/386#discussion_r1511235353
##########
src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java:
##########
@@ -268,7 +278,15 @@ public static String detect(final InputStream in) throws ArchiveException {
try {
tais = new TarArchiveInputStream(new ByteArrayInputStream(tarHeader));
// COMPRESS-191 - verify the header checksum
- if (tais.getNextTarEntry().isCheckSumOK()) {
+ // COMPRESS-644 - do not allow zero byte file entries
+ TarArchiveEntry tae = tais.getNextTarEntry();
+ //try to find the first non-directory entry within the first 10 entries.
+ int count = 0;
+ while (tae != null && tae.isDirectory() && count++ < MAX_TAR_RECORDS) {
Review Comment:
This causes detection to fail for `src/test/resources/COMPRESS-612/test-times-star-folder.tar` (once you rebase on git master which tests more files).
##########
src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java:
##########
@@ -141,4 +145,14 @@ public void testEmptyJarArchive() throws Exception {
public void testEmptyZipArchive() throws Exception {
checkEmptyArchive("zip");
}
+
+ @Test
+ public void ignoreZeroByteEntryInTarDetect_COMPRESS644() throws IOException {
Review Comment:
IOException is not thrown here, so it shouldn't be in the method signature.
--
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-644 -- do not allow zero by entries when detecting magic-less tar [commons-compress]
Posted by "tballison (via GitHub)" <gi...@apache.org>.
tballison commented on PR #386:
URL: https://github.com/apache/commons-compress/pull/386#issuecomment-2449854654
It looks like the changes here were accepted. I'm closing out this PR. Thank you @garydgregory and team!
--
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