Skip to content

Commit

Permalink
[COMPRESS-661] ArchiveInputStream markSupported should always return
Browse files Browse the repository at this point in the history
false
  • Loading branch information
garydgregory committed Mar 5, 2024
1 parent 9c82300 commit 91754ac
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" issue="COMPRESS-664" dev="ggregory" due-to="Elliotte Rusty Harold">Remove unused variables in tests #487.</action>
<action type="fix" issue="COMPRESS-666" dev="ggregory" due-to="Cosmin Carabet, Gary Gregory">Multithreaded access to Tar archive throws java.util.zip.ZipException: Corrupt GZIP trailer.</action>
<action type="fix" issue="COMPRESS-644" dev="ggregory" due-to="Tim Allison, Gary Gregory">ArchiveStreamFactory.detect(InputStream) returns TAR for ICO file #386.</action>
<action type="fix" issue="COMPRESS-661" dev="ggregory" due-to="Alexander Veit, Tilman Hausherr, Gary Gregory">ArchiveInputStream markSupported should always return false.</action>
<!-- REMOVE -->
<action type="remove" issue="COMPRESS-662" dev="ggregory" due-to="Christoph Loy, Gary Gregory">Remove out of date jar and scripts #483.</action>
</release>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,30 @@ public int getCount() {
*/
public abstract E getNextEntry() throws IOException;

/**
* Does nothing.
*
* TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.
*
* @param readlimit ignored.
*/
@Override
public synchronized void mark(final int readlimit) {
// noop
}

/**
* Always returns false.
*
* TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.
*
* @return Always returns false.
*/
@Override
public boolean markSupported() {
return false;
}

/**
* Decrements the counter of already read bytes.
*
Expand All @@ -186,4 +210,13 @@ public int read() throws IOException {
return num == -1 ? -1 : single[0] & BYTE_MASK;
}

/**
* Does nothing.
*
* TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.
*/
@Override
public synchronized void reset() {
// noop
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@ public void testCantReadWithoutOpeningAnEntry() throws Exception {
}
}

@Test
public void testCompress661() throws IOException {
testCompress661(false);
testCompress661(true);
}

private void testCompress661(final boolean checkMarkReadReset) throws IOException {
try (InputStream in = newInputStream("org/apache/commons/compress/COMPRESS-661/testARofText.ar");
ArArchiveInputStream archive = new ArArchiveInputStream(new BufferedInputStream(in))) {
assertNotNull(archive.getNextEntry());
if (checkMarkReadReset && archive.markSupported()) {
// mark() shouldn't be supported, but if it would be,
// mark+read+reset should not do any harm.
archive.mark(10);
archive.read(new byte[10]);
archive.reset();
}
final byte[] ba = IOUtils.toByteArray(archive);
assertEquals("Test d'indexation de Txt\nhttp://www.apache.org\n", new String(ba));
assertEquals(-1, archive.read());
assertEquals(-1, archive.read());
assertNull(archive.getNextEntry());
}
}

@Test
public void testInvalidBadTableLength() throws Exception {
try (InputStream in = newInputStream("org/apache/commons/compress/ar/number_parsing/bad_table_length_gnu-fail.ar");
Expand Down

0 comments on commit 91754ac

Please sign in to comment.