Add files using upload-large-folder tool
Browse files- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_winrar/file_to_compare_1 +1297 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/file_to_compare_1 +38 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/file_to_compare_2 +79 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/META-INF/services/org.apache.commons.compress.compressors.CompressorStreamProvider +1 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/COMPRESS-644/ARW05UP.ICO +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/COMPRESS-649/some-900kb-text.txt +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/COMPRESS-661/testARofText.ar +5 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_group-fail.ar +8 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_length-fail.ar +8 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_long_namelen_bsd-fail.ar +5 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_long_namelen_gnu1-fail.ar +8 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_long_namelen_gnu2-fail.ar +6 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_long_namelen_gnu3-fail.ar +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_modified-fail.ar +8 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_table_length_gnu-fail.ar +8 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_user-fail.ar +8 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/arj/zero_sized_headers-fail.arj +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/cpio/bad_long_value.cpio +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/dump/directory_null_bytes-fail.dump +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/dump/invalid_compression_type-fail.dump +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/dump/looping_inodes-fail.dump +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/dump/reclen_zero-fail.dump +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/fuzz/crash-f2efd9eaeb86cda597d07b5e3c3d81363633c2da +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ico/commons-daemon/procrunr.ico +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ico/commons-daemon/procruns.ico +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ico/commons-daemon/procrunw.ico +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ico/commons-imaging/OutOfMemory_epine.ico +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/bandint_oom.pack +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/cpfloat_oom.pack +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/cputf8_oom.pack +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/favoured_oom.pack +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/filebits_oom.pack +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/flags_oom.pack +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/references_oom.pack +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/segment_header_oom.pack +0 -0
- local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/signatures_oom.pack +0 -0
- local-test-commons-compress-delta-03/fuzz-tooling/docs/assets/css/just-the-docs-wider.scss +3 -0
- local-test-commons-compress-delta-03/fuzz-tooling/docs/getting-started/new-project-guide/swift_lang.md +78 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/.vscodeignore +10 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/README.md +17 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commandUtils.ts +17 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspace.ts +80 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdCreateOSSFuzzSetup.ts +28 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdFIGetOptimalTargets.ts +21 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdReproduceTestcase.ts +167 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupOSSFuzz.ts +53 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzerCFLite.ts +89 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/coverageHelper.ts +300 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/extension.ts +227 -0
- local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/fuzzIntrospectorHelper.ts +117 -0
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_winrar/file_to_compare_1
ADDED
|
@@ -0,0 +1,1297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 3 |
+
* or more contributor license agreements. See the NOTICE file
|
| 4 |
+
* distributed with this work for additional information
|
| 5 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 6 |
+
* to you under the Apache License, Version 2.0 (the
|
| 7 |
+
* "License"); you may not use this file except in compliance
|
| 8 |
+
* with the License. You may obtain a copy of the License at
|
| 9 |
+
*
|
| 10 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
*
|
| 12 |
+
* Unless required by applicable law or agreed to in writing,
|
| 13 |
+
* software distributed under the License is distributed on an
|
| 14 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 15 |
+
* KIND, either express or implied. See the License for the
|
| 16 |
+
* specific language governing permissions and limitations
|
| 17 |
+
* under the License.
|
| 18 |
+
*/
|
| 19 |
+
package org.apache.commons.compress.archivers.zip;
|
| 20 |
+
|
| 21 |
+
import java.io.ByteArrayInputStream;
|
| 22 |
+
import java.io.ByteArrayOutputStream;
|
| 23 |
+
import java.io.EOFException;
|
| 24 |
+
import java.io.IOException;
|
| 25 |
+
import java.io.InputStream;
|
| 26 |
+
import java.io.PushbackInputStream;
|
| 27 |
+
import java.math.BigInteger;
|
| 28 |
+
import java.nio.ByteBuffer;
|
| 29 |
+
import java.util.Arrays;
|
| 30 |
+
import java.util.zip.CRC32;
|
| 31 |
+
import java.util.zip.DataFormatException;
|
| 32 |
+
import java.util.zip.Inflater;
|
| 33 |
+
import java.util.zip.ZipEntry;
|
| 34 |
+
import java.util.zip.ZipException;
|
| 35 |
+
|
| 36 |
+
import org.apache.commons.compress.archivers.ArchiveEntry;
|
| 37 |
+
import org.apache.commons.compress.archivers.ArchiveInputStream;
|
| 38 |
+
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
|
| 39 |
+
import org.apache.commons.compress.compressors.deflate64.Deflate64CompressorInputStream;
|
| 40 |
+
import org.apache.commons.compress.utils.ArchiveUtils;
|
| 41 |
+
import org.apache.commons.compress.utils.IOUtils;
|
| 42 |
+
import org.apache.commons.compress.utils.InputStreamStatistics;
|
| 43 |
+
|
| 44 |
+
import static org.apache.commons.compress.archivers.zip.ZipConstants.DWORD;
|
| 45 |
+
import static org.apache.commons.compress.archivers.zip.ZipConstants.SHORT;
|
| 46 |
+
import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
|
| 47 |
+
import static org.apache.commons.compress.archivers.zip.ZipConstants.ZIP64_MAGIC;
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Implements an input stream that can read Zip archives.
|
| 51 |
+
*
|
| 52 |
+
* <p>As of Apache Commons Compress it transparently supports Zip64
|
| 53 |
+
* extensions and thus individual entries and archives larger than 4
|
| 54 |
+
* GB or with more than 65536 entries.</p>
|
| 55 |
+
*
|
| 56 |
+
* <p>The {@link ZipFile} class is preferred when reading from files
|
| 57 |
+
* as {@link ZipArchiveInputStream} is limited by not being able to
|
| 58 |
+
* read the central directory header before returning entries. In
|
| 59 |
+
* particular {@link ZipArchiveInputStream}</p>
|
| 60 |
+
*
|
| 61 |
+
* <ul>
|
| 62 |
+
*
|
| 63 |
+
* <li>may return entries that are not part of the central directory
|
| 64 |
+
* at all and shouldn't be considered part of the archive.</li>
|
| 65 |
+
*
|
| 66 |
+
* <li>may return several entries with the same name.</li>
|
| 67 |
+
*
|
| 68 |
+
* <li>will not return internal or external attributes.</li>
|
| 69 |
+
*
|
| 70 |
+
* <li>may return incomplete extra field data.</li>
|
| 71 |
+
*
|
| 72 |
+
* <li>may return unknown sizes and CRC values for entries until the
|
| 73 |
+
* next entry has been reached if the archive uses the data
|
| 74 |
+
* descriptor feature.</li>
|
| 75 |
+
*
|
| 76 |
+
* </ul>
|
| 77 |
+
*
|
| 78 |
+
* @see ZipFile
|
| 79 |
+
* @NotThreadSafe
|
| 80 |
+
*/
|
| 81 |
+
public class ZipArchiveInputStream extends ArchiveInputStream implements InputStreamStatistics {
|
| 82 |
+
|
| 83 |
+
/** The zip encoding to use for file names and the file comment. */
|
| 84 |
+
private final ZipEncoding zipEncoding;
|
| 85 |
+
|
| 86 |
+
// the provided encoding (for unit tests)
|
| 87 |
+
final String encoding;
|
| 88 |
+
|
| 89 |
+
/** Whether to look for and use Unicode extra fields. */
|
| 90 |
+
private final boolean useUnicodeExtraFields;
|
| 91 |
+
|
| 92 |
+
/** Wrapped stream, will always be a PushbackInputStream. */
|
| 93 |
+
private final InputStream in;
|
| 94 |
+
|
| 95 |
+
/** Inflater used for all deflated entries. */
|
| 96 |
+
private final Inflater inf = new Inflater(true);
|
| 97 |
+
|
| 98 |
+
/** Buffer used to read from the wrapped stream. */
|
| 99 |
+
private final ByteBuffer buf = ByteBuffer.allocate(ZipArchiveOutputStream.BUFFER_SIZE);
|
| 100 |
+
|
| 101 |
+
/** The entry that is currently being read. */
|
| 102 |
+
private CurrentEntry current = null;
|
| 103 |
+
|
| 104 |
+
/** Whether the stream has been closed. */
|
| 105 |
+
private boolean closed = false;
|
| 106 |
+
|
| 107 |
+
/** Whether the stream has reached the central directory - and thus found all entries. */
|
| 108 |
+
private boolean hitCentralDirectory = false;
|
| 109 |
+
|
| 110 |
+
/**
|
| 111 |
+
* When reading a stored entry that uses the data descriptor this
|
| 112 |
+
* stream has to read the full entry and caches it. This is the
|
| 113 |
+
* cache.
|
| 114 |
+
*/
|
| 115 |
+
private ByteArrayInputStream lastStoredEntry = null;
|
| 116 |
+
|
| 117 |
+
/** Whether the stream will try to read STORED entries that use a data descriptor. */
|
| 118 |
+
private boolean allowStoredEntriesWithDataDescriptor = false;
|
| 119 |
+
|
| 120 |
+
/** Count decompressed bytes for current entry */
|
| 121 |
+
private long uncompressedCount = 0;
|
| 122 |
+
|
| 123 |
+
private static final int LFH_LEN = 30;
|
| 124 |
+
/*
|
| 125 |
+
local file header signature WORD
|
| 126 |
+
version needed to extract SHORT
|
| 127 |
+
general purpose bit flag SHORT
|
| 128 |
+
compression method SHORT
|
| 129 |
+
last mod file time SHORT
|
| 130 |
+
last mod file date SHORT
|
| 131 |
+
crc-32 WORD
|
| 132 |
+
compressed size WORD
|
| 133 |
+
uncompressed size WORD
|
| 134 |
+
file name length SHORT
|
| 135 |
+
extra field length SHORT
|
| 136 |
+
*/
|
| 137 |
+
|
| 138 |
+
private static final int CFH_LEN = 46;
|
| 139 |
+
/*
|
| 140 |
+
central file header signature WORD
|
| 141 |
+
version made by SHORT
|
| 142 |
+
version needed to extract SHORT
|
| 143 |
+
general purpose bit flag SHORT
|
| 144 |
+
compression method SHORT
|
| 145 |
+
last mod file time SHORT
|
| 146 |
+
last mod file date SHORT
|
| 147 |
+
crc-32 WORD
|
| 148 |
+
compressed size WORD
|
| 149 |
+
uncompressed size WORD
|
| 150 |
+
file name length SHORT
|
| 151 |
+
extra field length SHORT
|
| 152 |
+
file comment length SHORT
|
| 153 |
+
disk number start SHORT
|
| 154 |
+
internal file attributes SHORT
|
| 155 |
+
external file attributes WORD
|
| 156 |
+
relative offset of local header WORD
|
| 157 |
+
*/
|
| 158 |
+
|
| 159 |
+
private static final long TWO_EXP_32 = ZIP64_MAGIC + 1;
|
| 160 |
+
|
| 161 |
+
// cached buffers - must only be used locally in the class (COMPRESS-172 - reduce garbage collection)
|
| 162 |
+
private final byte[] lfhBuf = new byte[LFH_LEN];
|
| 163 |
+
private final byte[] skipBuf = new byte[1024];
|
| 164 |
+
private final byte[] shortBuf = new byte[SHORT];
|
| 165 |
+
private final byte[] wordBuf = new byte[WORD];
|
| 166 |
+
private final byte[] twoDwordBuf = new byte[2 * DWORD];
|
| 167 |
+
|
| 168 |
+
private int entriesRead = 0;
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
* Create an instance using UTF-8 encoding
|
| 172 |
+
* @param inputStream the stream to wrap
|
| 173 |
+
*/
|
| 174 |
+
public ZipArchiveInputStream(final InputStream inputStream) {
|
| 175 |
+
this(inputStream, ZipEncodingHelper.UTF8);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* Create an instance using the specified encoding
|
| 180 |
+
* @param inputStream the stream to wrap
|
| 181 |
+
* @param encoding the encoding to use for file names, use null
|
| 182 |
+
* for the platform's default encoding
|
| 183 |
+
* @since 1.5
|
| 184 |
+
*/
|
| 185 |
+
public ZipArchiveInputStream(final InputStream inputStream, final String encoding) {
|
| 186 |
+
this(inputStream, encoding, true);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/**
|
| 190 |
+
* Create an instance using the specified encoding
|
| 191 |
+
* @param inputStream the stream to wrap
|
| 192 |
+
* @param encoding the encoding to use for file names, use null
|
| 193 |
+
* for the platform's default encoding
|
| 194 |
+
* @param useUnicodeExtraFields whether to use InfoZIP Unicode
|
| 195 |
+
* Extra Fields (if present) to set the file names.
|
| 196 |
+
*/
|
| 197 |
+
public ZipArchiveInputStream(final InputStream inputStream, final String encoding, final boolean useUnicodeExtraFields) {
|
| 198 |
+
this(inputStream, encoding, useUnicodeExtraFields, false);
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
/**
|
| 202 |
+
* Create an instance using the specified encoding
|
| 203 |
+
* @param inputStream the stream to wrap
|
| 204 |
+
* @param encoding the encoding to use for file names, use null
|
| 205 |
+
* for the platform's default encoding
|
| 206 |
+
* @param useUnicodeExtraFields whether to use InfoZIP Unicode
|
| 207 |
+
* Extra Fields (if present) to set the file names.
|
| 208 |
+
* @param allowStoredEntriesWithDataDescriptor whether the stream
|
| 209 |
+
* will try to read STORED entries that use a data descriptor
|
| 210 |
+
* @since 1.1
|
| 211 |
+
*/
|
| 212 |
+
public ZipArchiveInputStream(final InputStream inputStream,
|
| 213 |
+
final String encoding,
|
| 214 |
+
final boolean useUnicodeExtraFields,
|
| 215 |
+
final boolean allowStoredEntriesWithDataDescriptor) {
|
| 216 |
+
this.encoding = encoding;
|
| 217 |
+
zipEncoding = ZipEncodingHelper.getZipEncoding(encoding);
|
| 218 |
+
this.useUnicodeExtraFields = useUnicodeExtraFields;
|
| 219 |
+
in = new PushbackInputStream(inputStream, buf.capacity());
|
| 220 |
+
this.allowStoredEntriesWithDataDescriptor =
|
| 221 |
+
allowStoredEntriesWithDataDescriptor;
|
| 222 |
+
// haven't read anything so far
|
| 223 |
+
buf.limit(0);
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
public ZipArchiveEntry getNextZipEntry() throws IOException {
|
| 227 |
+
uncompressedCount = 0;
|
| 228 |
+
|
| 229 |
+
boolean firstEntry = true;
|
| 230 |
+
if (closed || hitCentralDirectory) {
|
| 231 |
+
return null;
|
| 232 |
+
}
|
| 233 |
+
if (current != null) {
|
| 234 |
+
closeEntry();
|
| 235 |
+
firstEntry = false;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
long currentHeaderOffset = getBytesRead();
|
| 239 |
+
try {
|
| 240 |
+
if (firstEntry) {
|
| 241 |
+
// split archives have a special signature before the
|
| 242 |
+
// first local file header - look for it and fail with
|
| 243 |
+
// the appropriate error message if this is a split
|
| 244 |
+
// archive.
|
| 245 |
+
readFirstLocalFileHeader(lfhBuf);
|
| 246 |
+
} else {
|
| 247 |
+
readFully(lfhBuf);
|
| 248 |
+
}
|
| 249 |
+
} catch (final EOFException e) { //NOSONAR
|
| 250 |
+
return null;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
final ZipLong sig = new ZipLong(lfhBuf);
|
| 254 |
+
if (!sig.equals(ZipLong.LFH_SIG)) {
|
| 255 |
+
if (sig.equals(ZipLong.CFH_SIG) || sig.equals(ZipLong.AED_SIG) || isApkSigningBlock(lfhBuf)) {
|
| 256 |
+
hitCentralDirectory = true;
|
| 257 |
+
skipRemainderOfArchive();
|
| 258 |
+
return null;
|
| 259 |
+
}
|
| 260 |
+
throw new ZipException(String.format("Unexpected record signature: 0X%X", sig.getValue()));
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
int off = WORD;
|
| 264 |
+
current = new CurrentEntry();
|
| 265 |
+
|
| 266 |
+
final int versionMadeBy = ZipShort.getValue(lfhBuf, off);
|
| 267 |
+
off += SHORT;
|
| 268 |
+
current.entry.setPlatform((versionMadeBy >> ZipFile.BYTE_SHIFT) & ZipFile.NIBLET_MASK);
|
| 269 |
+
|
| 270 |
+
final GeneralPurposeBit gpFlag = GeneralPurposeBit.parse(lfhBuf, off);
|
| 271 |
+
final boolean hasUTF8Flag = gpFlag.usesUTF8ForNames();
|
| 272 |
+
final ZipEncoding entryEncoding = hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
|
| 273 |
+
current.hasDataDescriptor = gpFlag.usesDataDescriptor();
|
| 274 |
+
current.entry.setGeneralPurposeBit(gpFlag);
|
| 275 |
+
|
| 276 |
+
off += SHORT;
|
| 277 |
+
|
| 278 |
+
current.entry.setMethod(ZipShort.getValue(lfhBuf, off));
|
| 279 |
+
off += SHORT;
|
| 280 |
+
|
| 281 |
+
final long time = ZipUtil.dosToJavaTime(ZipLong.getValue(lfhBuf, off));
|
| 282 |
+
current.entry.setTime(time);
|
| 283 |
+
off += WORD;
|
| 284 |
+
|
| 285 |
+
ZipLong size = null, cSize = null;
|
| 286 |
+
if (!current.hasDataDescriptor) {
|
| 287 |
+
current.entry.setCrc(ZipLong.getValue(lfhBuf, off));
|
| 288 |
+
off += WORD;
|
| 289 |
+
|
| 290 |
+
cSize = new ZipLong(lfhBuf, off);
|
| 291 |
+
off += WORD;
|
| 292 |
+
|
| 293 |
+
size = new ZipLong(lfhBuf, off);
|
| 294 |
+
off += WORD;
|
| 295 |
+
} else {
|
| 296 |
+
off += 3 * WORD;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
final int fileNameLen = ZipShort.getValue(lfhBuf, off);
|
| 300 |
+
|
| 301 |
+
off += SHORT;
|
| 302 |
+
|
| 303 |
+
final int extraLen = ZipShort.getValue(lfhBuf, off);
|
| 304 |
+
off += SHORT; // NOSONAR - assignment as documentation
|
| 305 |
+
|
| 306 |
+
final byte[] fileName = new byte[fileNameLen];
|
| 307 |
+
readFully(fileName);
|
| 308 |
+
current.entry.setName(entryEncoding.decode(fileName), fileName);
|
| 309 |
+
if (hasUTF8Flag) {
|
| 310 |
+
current.entry.setNameSource(ZipArchiveEntry.NameSource.NAME_WITH_EFS_FLAG);
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
final byte[] extraData = new byte[extraLen];
|
| 314 |
+
readFully(extraData);
|
| 315 |
+
current.entry.setExtra(extraData);
|
| 316 |
+
|
| 317 |
+
if (!hasUTF8Flag && useUnicodeExtraFields) {
|
| 318 |
+
ZipUtil.setNameAndCommentFromExtraFields(current.entry, fileName, null);
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
processZip64Extra(size, cSize);
|
| 322 |
+
|
| 323 |
+
current.entry.setLocalHeaderOffset(currentHeaderOffset);
|
| 324 |
+
current.entry.setDataOffset(getBytesRead());
|
| 325 |
+
current.entry.setStreamContiguous(true);
|
| 326 |
+
|
| 327 |
+
ZipMethod m = ZipMethod.getMethodByCode(current.entry.getMethod());
|
| 328 |
+
if (current.entry.getCompressedSize() != ArchiveEntry.SIZE_UNKNOWN) {
|
| 329 |
+
if (ZipUtil.canHandleEntryData(current.entry) && m != ZipMethod.STORED && m != ZipMethod.DEFLATED) {
|
| 330 |
+
InputStream bis = new BoundedInputStream(in, current.entry.getCompressedSize());
|
| 331 |
+
switch (m) {
|
| 332 |
+
case UNSHRINKING:
|
| 333 |
+
current.in = new UnshrinkingInputStream(bis);
|
| 334 |
+
break;
|
| 335 |
+
case IMPLODING:
|
| 336 |
+
current.in = new ExplodingInputStream(
|
| 337 |
+
current.entry.getGeneralPurposeBit().getSlidingDictionarySize(),
|
| 338 |
+
current.entry.getGeneralPurposeBit().getNumberOfShannonFanoTrees(),
|
| 339 |
+
bis);
|
| 340 |
+
break;
|
| 341 |
+
case BZIP2:
|
| 342 |
+
current.in = new BZip2CompressorInputStream(bis);
|
| 343 |
+
break;
|
| 344 |
+
case ENHANCED_DEFLATED:
|
| 345 |
+
current.in = new Deflate64CompressorInputStream(bis);
|
| 346 |
+
break;
|
| 347 |
+
default:
|
| 348 |
+
// we should never get here as all supported methods have been covered
|
| 349 |
+
// will cause an error when read is invoked, don't throw an exception here so people can
|
| 350 |
+
// skip unsupported entries
|
| 351 |
+
break;
|
| 352 |
+
}
|
| 353 |
+
}
|
| 354 |
+
} else if (m == ZipMethod.ENHANCED_DEFLATED) {
|
| 355 |
+
current.in = new Deflate64CompressorInputStream(in);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
entriesRead++;
|
| 359 |
+
return current.entry;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
/**
|
| 363 |
+
* Fills the given array with the first local file header and
|
| 364 |
+
* deals with splitting/spanning markers that may prefix the first
|
| 365 |
+
* LFH.
|
| 366 |
+
*/
|
| 367 |
+
private void readFirstLocalFileHeader(final byte[] lfh) throws IOException {
|
| 368 |
+
readFully(lfh);
|
| 369 |
+
final ZipLong sig = new ZipLong(lfh);
|
| 370 |
+
if (sig.equals(ZipLong.DD_SIG)) {
|
| 371 |
+
throw new UnsupportedZipFeatureException(UnsupportedZipFeatureException.Feature.SPLITTING);
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
if (sig.equals(ZipLong.SINGLE_SEGMENT_SPLIT_MARKER)) {
|
| 375 |
+
// The archive is not really split as only one segment was
|
| 376 |
+
// needed in the end. Just skip over the marker.
|
| 377 |
+
final byte[] missedLfhBytes = new byte[4];
|
| 378 |
+
readFully(missedLfhBytes);
|
| 379 |
+
System.arraycopy(lfh, 4, lfh, 0, LFH_LEN - 4);
|
| 380 |
+
System.arraycopy(missedLfhBytes, 0, lfh, LFH_LEN - 4, 4);
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
/**
|
| 385 |
+
* Records whether a Zip64 extra is present and sets the size
|
| 386 |
+
* information from it if sizes are 0xFFFFFFFF and the entry
|
| 387 |
+
* doesn't use a data descriptor.
|
| 388 |
+
*/
|
| 389 |
+
private void processZip64Extra(final ZipLong size, final ZipLong cSize) {
|
| 390 |
+
final Zip64ExtendedInformationExtraField z64 =
|
| 391 |
+
(Zip64ExtendedInformationExtraField)
|
| 392 |
+
current.entry.getExtraField(Zip64ExtendedInformationExtraField.HEADER_ID);
|
| 393 |
+
current.usesZip64 = z64 != null;
|
| 394 |
+
if (!current.hasDataDescriptor) {
|
| 395 |
+
if (z64 != null // same as current.usesZip64 but avoids NPE warning
|
| 396 |
+
&& (ZipLong.ZIP64_MAGIC.equals(cSize) || ZipLong.ZIP64_MAGIC.equals(size)) ) {
|
| 397 |
+
current.entry.setCompressedSize(z64.getCompressedSize().getLongValue());
|
| 398 |
+
current.entry.setSize(z64.getSize().getLongValue());
|
| 399 |
+
} else if (cSize != null && size != null) {
|
| 400 |
+
current.entry.setCompressedSize(cSize.getValue());
|
| 401 |
+
current.entry.setSize(size.getValue());
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
@Override
|
| 407 |
+
public ArchiveEntry getNextEntry() throws IOException {
|
| 408 |
+
return getNextZipEntry();
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
/**
|
| 412 |
+
* Whether this class is able to read the given entry.
|
| 413 |
+
*
|
| 414 |
+
* <p>May return false if it is set up to use encryption or a
|
| 415 |
+
* compression method that hasn't been implemented yet.</p>
|
| 416 |
+
* @since 1.1
|
| 417 |
+
*/
|
| 418 |
+
@Override
|
| 419 |
+
public boolean canReadEntryData(final ArchiveEntry ae) {
|
| 420 |
+
if (ae instanceof ZipArchiveEntry) {
|
| 421 |
+
final ZipArchiveEntry ze = (ZipArchiveEntry) ae;
|
| 422 |
+
return ZipUtil.canHandleEntryData(ze)
|
| 423 |
+
&& supportsDataDescriptorFor(ze)
|
| 424 |
+
&& supportsCompressedSizeFor(ze);
|
| 425 |
+
}
|
| 426 |
+
return false;
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
@Override
|
| 430 |
+
public int read(final byte[] buffer, final int offset, final int length) throws IOException {
|
| 431 |
+
if (length == 0) {
|
| 432 |
+
return 0;
|
| 433 |
+
}
|
| 434 |
+
if (closed) {
|
| 435 |
+
throw new IOException("The stream is closed");
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
if (current == null) {
|
| 439 |
+
return -1;
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
// avoid int overflow, check null buffer
|
| 443 |
+
if (offset > buffer.length || length < 0 || offset < 0 || buffer.length - offset < length) {
|
| 444 |
+
throw new ArrayIndexOutOfBoundsException();
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
ZipUtil.checkRequestedFeatures(current.entry);
|
| 448 |
+
if (!supportsDataDescriptorFor(current.entry)) {
|
| 449 |
+
throw new UnsupportedZipFeatureException(UnsupportedZipFeatureException.Feature.DATA_DESCRIPTOR,
|
| 450 |
+
current.entry);
|
| 451 |
+
}
|
| 452 |
+
if (!supportsCompressedSizeFor(current.entry)) {
|
| 453 |
+
throw new UnsupportedZipFeatureException(UnsupportedZipFeatureException.Feature.UNKNOWN_COMPRESSED_SIZE,
|
| 454 |
+
current.entry);
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
int read;
|
| 458 |
+
if (current.entry.getMethod() == ZipArchiveOutputStream.STORED) {
|
| 459 |
+
read = readStored(buffer, offset, length);
|
| 460 |
+
} else if (current.entry.getMethod() == ZipArchiveOutputStream.DEFLATED) {
|
| 461 |
+
read = readDeflated(buffer, offset, length);
|
| 462 |
+
} else if (current.entry.getMethod() == ZipMethod.UNSHRINKING.getCode()
|
| 463 |
+
|| current.entry.getMethod() == ZipMethod.IMPLODING.getCode()
|
| 464 |
+
|| current.entry.getMethod() == ZipMethod.ENHANCED_DEFLATED.getCode()
|
| 465 |
+
|| current.entry.getMethod() == ZipMethod.BZIP2.getCode()) {
|
| 466 |
+
read = current.in.read(buffer, offset, length);
|
| 467 |
+
} else {
|
| 468 |
+
throw new UnsupportedZipFeatureException(ZipMethod.getMethodByCode(current.entry.getMethod()),
|
| 469 |
+
current.entry);
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
if (read >= 0) {
|
| 473 |
+
current.crc.update(buffer, offset, read);
|
| 474 |
+
uncompressedCount += read;
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
return read;
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
/**
|
| 481 |
+
* @since 1.17
|
| 482 |
+
*/
|
| 483 |
+
@Override
|
| 484 |
+
public long getCompressedCount() {
|
| 485 |
+
if (current.entry.getMethod() == ZipArchiveOutputStream.STORED) {
|
| 486 |
+
return current.bytesRead;
|
| 487 |
+
} else if (current.entry.getMethod() == ZipArchiveOutputStream.DEFLATED) {
|
| 488 |
+
return getBytesInflated();
|
| 489 |
+
} else if (current.entry.getMethod() == ZipMethod.UNSHRINKING.getCode()) {
|
| 490 |
+
return ((UnshrinkingInputStream) current.in).getCompressedCount();
|
| 491 |
+
} else if (current.entry.getMethod() == ZipMethod.IMPLODING.getCode()) {
|
| 492 |
+
return ((ExplodingInputStream) current.in).getCompressedCount();
|
| 493 |
+
} else if (current.entry.getMethod() == ZipMethod.ENHANCED_DEFLATED.getCode()) {
|
| 494 |
+
return ((Deflate64CompressorInputStream) current.in).getCompressedCount();
|
| 495 |
+
} else if (current.entry.getMethod() == ZipMethod.BZIP2.getCode()) {
|
| 496 |
+
return ((BZip2CompressorInputStream) current.in).getCompressedCount();
|
| 497 |
+
} else {
|
| 498 |
+
return -1;
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
/**
|
| 503 |
+
* @since 1.17
|
| 504 |
+
*/
|
| 505 |
+
@Override
|
| 506 |
+
public long getUncompressedCount() {
|
| 507 |
+
return uncompressedCount;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
/**
|
| 511 |
+
* Implementation of read for STORED entries.
|
| 512 |
+
*/
|
| 513 |
+
private int readStored(final byte[] buffer, final int offset, final int length) throws IOException {
|
| 514 |
+
|
| 515 |
+
if (current.hasDataDescriptor) {
|
| 516 |
+
if (lastStoredEntry == null) {
|
| 517 |
+
readStoredEntry();
|
| 518 |
+
}
|
| 519 |
+
return lastStoredEntry.read(buffer, offset, length);
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
final long csize = current.entry.getSize();
|
| 523 |
+
if (current.bytesRead >= csize) {
|
| 524 |
+
return -1;
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
if (buf.position() >= buf.limit()) {
|
| 528 |
+
buf.position(0);
|
| 529 |
+
final int l = in.read(buf.array());
|
| 530 |
+
if (l == -1) {
|
| 531 |
+
buf.limit(0);
|
| 532 |
+
throw new IOException("Truncated ZIP file");
|
| 533 |
+
}
|
| 534 |
+
buf.limit(l);
|
| 535 |
+
|
| 536 |
+
count(l);
|
| 537 |
+
current.bytesReadFromStream += l;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
int toRead = Math.min(buf.remaining(), length);
|
| 541 |
+
if ((csize - current.bytesRead) < toRead) {
|
| 542 |
+
// if it is smaller than toRead then it fits into an int
|
| 543 |
+
toRead = (int) (csize - current.bytesRead);
|
| 544 |
+
}
|
| 545 |
+
buf.get(buffer, offset, toRead);
|
| 546 |
+
current.bytesRead += toRead;
|
| 547 |
+
return toRead;
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
/**
|
| 551 |
+
* Implementation of read for DEFLATED entries.
|
| 552 |
+
*/
|
| 553 |
+
private int readDeflated(final byte[] buffer, final int offset, final int length) throws IOException {
|
| 554 |
+
final int read = readFromInflater(buffer, offset, length);
|
| 555 |
+
if (read <= 0) {
|
| 556 |
+
if (inf.finished()) {
|
| 557 |
+
return -1;
|
| 558 |
+
} else if (inf.needsDictionary()) {
|
| 559 |
+
throw new ZipException("This archive needs a preset dictionary"
|
| 560 |
+
+ " which is not supported by Commons"
|
| 561 |
+
+ " Compress.");
|
| 562 |
+
} else if (read == -1) {
|
| 563 |
+
throw new IOException("Truncated ZIP file");
|
| 564 |
+
}
|
| 565 |
+
}
|
| 566 |
+
return read;
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
/**
|
| 570 |
+
* Potentially reads more bytes to fill the inflater's buffer and
|
| 571 |
+
* reads from it.
|
| 572 |
+
*/
|
| 573 |
+
private int readFromInflater(final byte[] buffer, final int offset, final int length) throws IOException {
|
| 574 |
+
int read = 0;
|
| 575 |
+
do {
|
| 576 |
+
if (inf.needsInput()) {
|
| 577 |
+
final int l = fill();
|
| 578 |
+
if (l > 0) {
|
| 579 |
+
current.bytesReadFromStream += buf.limit();
|
| 580 |
+
} else if (l == -1) {
|
| 581 |
+
return -1;
|
| 582 |
+
} else {
|
| 583 |
+
break;
|
| 584 |
+
}
|
| 585 |
+
}
|
| 586 |
+
try {
|
| 587 |
+
read = inf.inflate(buffer, offset, length);
|
| 588 |
+
} catch (final DataFormatException e) {
|
| 589 |
+
throw (IOException) new ZipException(e.getMessage()).initCause(e);
|
| 590 |
+
}
|
| 591 |
+
} while (read == 0 && inf.needsInput());
|
| 592 |
+
return read;
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
@Override
|
| 596 |
+
public void close() throws IOException {
|
| 597 |
+
if (!closed) {
|
| 598 |
+
closed = true;
|
| 599 |
+
try {
|
| 600 |
+
in.close();
|
| 601 |
+
} finally {
|
| 602 |
+
inf.end();
|
| 603 |
+
}
|
| 604 |
+
}
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
/**
|
| 608 |
+
* Skips over and discards value bytes of data from this input
|
| 609 |
+
* stream.
|
| 610 |
+
*
|
| 611 |
+
* <p>This implementation may end up skipping over some smaller
|
| 612 |
+
* number of bytes, possibly 0, if and only if it reaches the end
|
| 613 |
+
* of the underlying stream.</p>
|
| 614 |
+
*
|
| 615 |
+
* <p>The actual number of bytes skipped is returned.</p>
|
| 616 |
+
*
|
| 617 |
+
* @param value the number of bytes to be skipped.
|
| 618 |
+
* @return the actual number of bytes skipped.
|
| 619 |
+
* @throws IOException - if an I/O error occurs.
|
| 620 |
+
* @throws IllegalArgumentException - if value is negative.
|
| 621 |
+
*/
|
| 622 |
+
@Override
|
| 623 |
+
public long skip(final long value) throws IOException {
|
| 624 |
+
if (value >= 0) {
|
| 625 |
+
long skipped = 0;
|
| 626 |
+
while (skipped < value) {
|
| 627 |
+
final long rem = value - skipped;
|
| 628 |
+
final int x = read(skipBuf, 0, (int) (skipBuf.length > rem ? rem : skipBuf.length));
|
| 629 |
+
if (x == -1) {
|
| 630 |
+
return skipped;
|
| 631 |
+
}
|
| 632 |
+
skipped += x;
|
| 633 |
+
}
|
| 634 |
+
return skipped;
|
| 635 |
+
}
|
| 636 |
+
throw new IllegalArgumentException();
|
| 637 |
+
}
|
| 638 |
+
|
| 639 |
+
/**
|
| 640 |
+
* Checks if the signature matches what is expected for a zip file.
|
| 641 |
+
* Does not currently handle self-extracting zips which may have arbitrary
|
| 642 |
+
* leading content.
|
| 643 |
+
*
|
| 644 |
+
* @param signature the bytes to check
|
| 645 |
+
* @param length the number of bytes to check
|
| 646 |
+
* @return true, if this stream is a zip archive stream, false otherwise
|
| 647 |
+
*/
|
| 648 |
+
public static boolean matches(final byte[] signature, final int length) {
|
| 649 |
+
if (length < ZipArchiveOutputStream.LFH_SIG.length) {
|
| 650 |
+
return false;
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
return checksig(signature, ZipArchiveOutputStream.LFH_SIG) // normal file
|
| 654 |
+
|| checksig(signature, ZipArchiveOutputStream.EOCD_SIG) // empty zip
|
| 655 |
+
|| checksig(signature, ZipArchiveOutputStream.DD_SIG) // split zip
|
| 656 |
+
|| checksig(signature, ZipLong.SINGLE_SEGMENT_SPLIT_MARKER.getBytes());
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
private static boolean checksig(final byte[] signature, final byte[] expected) {
|
| 660 |
+
for (int i = 0; i < expected.length; i++) {
|
| 661 |
+
if (signature[i] != expected[i]) {
|
| 662 |
+
return false;
|
| 663 |
+
}
|
| 664 |
+
}
|
| 665 |
+
return true;
|
| 666 |
+
}
|
| 667 |
+
|
| 668 |
+
/**
|
| 669 |
+
* Closes the current ZIP archive entry and positions the underlying
|
| 670 |
+
* stream to the beginning of the next entry. All per-entry variables
|
| 671 |
+
* and data structures are cleared.
|
| 672 |
+
* <p>
|
| 673 |
+
* If the compressed size of this entry is included in the entry header,
|
| 674 |
+
* then any outstanding bytes are simply skipped from the underlying
|
| 675 |
+
* stream without uncompressing them. This allows an entry to be safely
|
| 676 |
+
* closed even if the compression method is unsupported.
|
| 677 |
+
* <p>
|
| 678 |
+
* In case we don't know the compressed size of this entry or have
|
| 679 |
+
* already buffered too much data from the underlying stream to support
|
| 680 |
+
* uncompression, then the uncompression process is completed and the
|
| 681 |
+
* end position of the stream is adjusted based on the result of that
|
| 682 |
+
* process.
|
| 683 |
+
*
|
| 684 |
+
* @throws IOException if an error occurs
|
| 685 |
+
*/
|
| 686 |
+
private void closeEntry() throws IOException {
|
| 687 |
+
if (closed) {
|
| 688 |
+
throw new IOException("The stream is closed");
|
| 689 |
+
}
|
| 690 |
+
if (current == null) {
|
| 691 |
+
return;
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
// Ensure all entry bytes are read
|
| 695 |
+
if (currentEntryHasOutstandingBytes()) {
|
| 696 |
+
drainCurrentEntryData();
|
| 697 |
+
} else {
|
| 698 |
+
// this is guaranteed to exhaust the stream
|
| 699 |
+
skip(Long.MAX_VALUE); //NOSONAR
|
| 700 |
+
|
| 701 |
+
final long inB = current.entry.getMethod() == ZipArchiveOutputStream.DEFLATED
|
| 702 |
+
? getBytesInflated() : current.bytesRead;
|
| 703 |
+
|
| 704 |
+
// this is at most a single read() operation and can't
|
| 705 |
+
// exceed the range of int
|
| 706 |
+
final int diff = (int) (current.bytesReadFromStream - inB);
|
| 707 |
+
|
| 708 |
+
// Pushback any required bytes
|
| 709 |
+
if (diff > 0) {
|
| 710 |
+
pushback(buf.array(), buf.limit() - diff, diff);
|
| 711 |
+
current.bytesReadFromStream -= diff;
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
// Drain remainder of entry if not all data bytes were required
|
| 715 |
+
if (currentEntryHasOutstandingBytes()) {
|
| 716 |
+
drainCurrentEntryData();
|
| 717 |
+
}
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
if (lastStoredEntry == null && current.hasDataDescriptor) {
|
| 721 |
+
readDataDescriptor();
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
inf.reset();
|
| 725 |
+
buf.clear().flip();
|
| 726 |
+
current = null;
|
| 727 |
+
lastStoredEntry = null;
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
/**
|
| 731 |
+
* If the compressed size of the current entry is included in the entry header
|
| 732 |
+
* and there are any outstanding bytes in the underlying stream, then
|
| 733 |
+
* this returns true.
|
| 734 |
+
*
|
| 735 |
+
* @return true, if current entry is determined to have outstanding bytes, false otherwise
|
| 736 |
+
*/
|
| 737 |
+
private boolean currentEntryHasOutstandingBytes() {
|
| 738 |
+
return current.bytesReadFromStream <= current.entry.getCompressedSize()
|
| 739 |
+
&& !current.hasDataDescriptor;
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
/**
|
| 743 |
+
* Read all data of the current entry from the underlying stream
|
| 744 |
+
* that hasn't been read, yet.
|
| 745 |
+
*/
|
| 746 |
+
private void drainCurrentEntryData() throws IOException {
|
| 747 |
+
long remaining = current.entry.getCompressedSize() - current.bytesReadFromStream;
|
| 748 |
+
while (remaining > 0) {
|
| 749 |
+
final long n = in.read(buf.array(), 0, (int) Math.min(buf.capacity(), remaining));
|
| 750 |
+
if (n < 0) {
|
| 751 |
+
throw new EOFException("Truncated ZIP entry: "
|
| 752 |
+
+ ArchiveUtils.sanitize(current.entry.getName()));
|
| 753 |
+
}
|
| 754 |
+
count(n);
|
| 755 |
+
remaining -= n;
|
| 756 |
+
}
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
/**
|
| 760 |
+
* Get the number of bytes Inflater has actually processed.
|
| 761 |
+
*
|
| 762 |
+
* <p>for Java < Java7 the getBytes* methods in
|
| 763 |
+
* Inflater/Deflater seem to return unsigned ints rather than
|
| 764 |
+
* longs that start over with 0 at 2^32.</p>
|
| 765 |
+
*
|
| 766 |
+
* <p>The stream knows how many bytes it has read, but not how
|
| 767 |
+
* many the Inflater actually consumed - it should be between the
|
| 768 |
+
* total number of bytes read for the entry and the total number
|
| 769 |
+
* minus the last read operation. Here we just try to make the
|
| 770 |
+
* value close enough to the bytes we've read by assuming the
|
| 771 |
+
* number of bytes consumed must be smaller than (or equal to) the
|
| 772 |
+
* number of bytes read but not smaller by more than 2^32.</p>
|
| 773 |
+
*/
|
| 774 |
+
private long getBytesInflated() {
|
| 775 |
+
long inB = inf.getBytesRead();
|
| 776 |
+
if (current.bytesReadFromStream >= TWO_EXP_32) {
|
| 777 |
+
while (inB + TWO_EXP_32 <= current.bytesReadFromStream) {
|
| 778 |
+
inB += TWO_EXP_32;
|
| 779 |
+
}
|
| 780 |
+
}
|
| 781 |
+
return inB;
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
private int fill() throws IOException {
|
| 785 |
+
if (closed) {
|
| 786 |
+
throw new IOException("The stream is closed");
|
| 787 |
+
}
|
| 788 |
+
final int length = in.read(buf.array());
|
| 789 |
+
if (length > 0) {
|
| 790 |
+
buf.limit(length);
|
| 791 |
+
count(buf.limit());
|
| 792 |
+
inf.setInput(buf.array(), 0, buf.limit());
|
| 793 |
+
}
|
| 794 |
+
return length;
|
| 795 |
+
}
|
| 796 |
+
|
| 797 |
+
private void readFully(final byte[] b) throws IOException {
|
| 798 |
+
readFully(b, 0);
|
| 799 |
+
}
|
| 800 |
+
|
| 801 |
+
private void readFully(final byte[] b, final int off) throws IOException {
|
| 802 |
+
final int len = b.length - off;
|
| 803 |
+
final int count = IOUtils.readFully(in, b, off, len);
|
| 804 |
+
count(count);
|
| 805 |
+
if (count < len) {
|
| 806 |
+
throw new EOFException();
|
| 807 |
+
}
|
| 808 |
+
}
|
| 809 |
+
|
| 810 |
+
private void readDataDescriptor() throws IOException {
|
| 811 |
+
readFully(wordBuf);
|
| 812 |
+
ZipLong val = new ZipLong(wordBuf);
|
| 813 |
+
if (ZipLong.DD_SIG.equals(val)) {
|
| 814 |
+
// data descriptor with signature, skip sig
|
| 815 |
+
readFully(wordBuf);
|
| 816 |
+
val = new ZipLong(wordBuf);
|
| 817 |
+
}
|
| 818 |
+
current.entry.setCrc(val.getValue());
|
| 819 |
+
|
| 820 |
+
// if there is a ZIP64 extra field, sizes are eight bytes
|
| 821 |
+
// each, otherwise four bytes each. Unfortunately some
|
| 822 |
+
// implementations - namely Java7 - use eight bytes without
|
| 823 |
+
// using a ZIP64 extra field -
|
| 824 |
+
// https://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7073588
|
| 825 |
+
|
| 826 |
+
// just read 16 bytes and check whether bytes nine to twelve
|
| 827 |
+
// look like one of the signatures of what could follow a data
|
| 828 |
+
// descriptor (ignoring archive decryption headers for now).
|
| 829 |
+
// If so, push back eight bytes and assume sizes are four
|
| 830 |
+
// bytes, otherwise sizes are eight bytes each.
|
| 831 |
+
readFully(twoDwordBuf);
|
| 832 |
+
final ZipLong potentialSig = new ZipLong(twoDwordBuf, DWORD);
|
| 833 |
+
if (potentialSig.equals(ZipLong.CFH_SIG) || potentialSig.equals(ZipLong.LFH_SIG)) {
|
| 834 |
+
pushback(twoDwordBuf, DWORD, DWORD);
|
| 835 |
+
current.entry.setCompressedSize(ZipLong.getValue(twoDwordBuf));
|
| 836 |
+
current.entry.setSize(ZipLong.getValue(twoDwordBuf, WORD));
|
| 837 |
+
} else {
|
| 838 |
+
current.entry.setCompressedSize(ZipEightByteInteger.getLongValue(twoDwordBuf));
|
| 839 |
+
current.entry.setSize(ZipEightByteInteger.getLongValue(twoDwordBuf, DWORD));
|
| 840 |
+
}
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
/**
|
| 844 |
+
* Whether this entry requires a data descriptor this library can work with.
|
| 845 |
+
*
|
| 846 |
+
* @return true if allowStoredEntriesWithDataDescriptor is true,
|
| 847 |
+
* the entry doesn't require any data descriptor or the method is
|
| 848 |
+
* DEFLATED or ENHANCED_DEFLATED.
|
| 849 |
+
*/
|
| 850 |
+
private boolean supportsDataDescriptorFor(final ZipArchiveEntry entry) {
|
| 851 |
+
return !entry.getGeneralPurposeBit().usesDataDescriptor()
|
| 852 |
+
|
| 853 |
+
|| (allowStoredEntriesWithDataDescriptor && entry.getMethod() == ZipEntry.STORED)
|
| 854 |
+
|| entry.getMethod() == ZipEntry.DEFLATED
|
| 855 |
+
|| entry.getMethod() == ZipMethod.ENHANCED_DEFLATED.getCode();
|
| 856 |
+
}
|
| 857 |
+
|
| 858 |
+
/**
|
| 859 |
+
* Whether the compressed size for the entry is either known or
|
| 860 |
+
* not required by the compression method being used.
|
| 861 |
+
*/
|
| 862 |
+
private boolean supportsCompressedSizeFor(final ZipArchiveEntry entry) {
|
| 863 |
+
return entry.getCompressedSize() != ArchiveEntry.SIZE_UNKNOWN
|
| 864 |
+
|| entry.getMethod() == ZipEntry.DEFLATED
|
| 865 |
+
|| entry.getMethod() == ZipMethod.ENHANCED_DEFLATED.getCode()
|
| 866 |
+
|| (entry.getGeneralPurposeBit().usesDataDescriptor()
|
| 867 |
+
&& allowStoredEntriesWithDataDescriptor
|
| 868 |
+
&& entry.getMethod() == ZipEntry.STORED);
|
| 869 |
+
}
|
| 870 |
+
|
| 871 |
+
private static final String USE_ZIPFILE_INSTEAD_OF_STREAM_DISCLAIMER =
|
| 872 |
+
" while reading a stored entry using data descriptor. Either the archive is broken"
|
| 873 |
+
+ " or it can not be read using ZipArchiveInputStream and you must use ZipFile."
|
| 874 |
+
+ " A common cause for this is a ZIP archive containing a ZIP archive."
|
| 875 |
+
+ " See http://commons.apache.org/proper/commons-compress/zip.html#ZipArchiveInputStream_vs_ZipFile";
|
| 876 |
+
|
| 877 |
+
/**
|
| 878 |
+
* Caches a stored entry that uses the data descriptor.
|
| 879 |
+
*
|
| 880 |
+
* <ul>
|
| 881 |
+
* <li>Reads a stored entry until the signature of a local file
|
| 882 |
+
* header, central directory header or data descriptor has been
|
| 883 |
+
* found.</li>
|
| 884 |
+
* <li>Stores all entry data in lastStoredEntry.</p>
|
| 885 |
+
* <li>Rewinds the stream to position at the data
|
| 886 |
+
* descriptor.</li>
|
| 887 |
+
* <li>reads the data descriptor</li>
|
| 888 |
+
* </ul>
|
| 889 |
+
*
|
| 890 |
+
* <p>After calling this method the entry should know its size,
|
| 891 |
+
* the entry's data is cached and the stream is positioned at the
|
| 892 |
+
* next local file or central directory header.</p>
|
| 893 |
+
*/
|
| 894 |
+
private void readStoredEntry() throws IOException {
|
| 895 |
+
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
| 896 |
+
int off = 0;
|
| 897 |
+
boolean done = false;
|
| 898 |
+
|
| 899 |
+
// length of DD without signature
|
| 900 |
+
final int ddLen = current.usesZip64 ? WORD + 2 * DWORD : 3 * WORD;
|
| 901 |
+
|
| 902 |
+
while (!done) {
|
| 903 |
+
final int r = in.read(buf.array(), off, ZipArchiveOutputStream.BUFFER_SIZE - off);
|
| 904 |
+
if (r <= 0) {
|
| 905 |
+
// read the whole archive without ever finding a
|
| 906 |
+
// central directory
|
| 907 |
+
throw new IOException("Truncated ZIP file");
|
| 908 |
+
}
|
| 909 |
+
if (r + off < 4) {
|
| 910 |
+
// buffer too small to check for a signature, loop
|
| 911 |
+
off += r;
|
| 912 |
+
continue;
|
| 913 |
+
}
|
| 914 |
+
|
| 915 |
+
done = bufferContainsSignature(bos, off, r, ddLen);
|
| 916 |
+
if (!done) {
|
| 917 |
+
off = cacheBytesRead(bos, off, r, ddLen);
|
| 918 |
+
}
|
| 919 |
+
}
|
| 920 |
+
if (current.entry.getCompressedSize() != current.entry.getSize()) {
|
| 921 |
+
throw new ZipException("compressed and uncompressed size don't match"
|
| 922 |
+
+ USE_ZIPFILE_INSTEAD_OF_STREAM_DISCLAIMER);
|
| 923 |
+
}
|
| 924 |
+
final byte[] b = bos.toByteArray();
|
| 925 |
+
if (b.length != current.entry.getSize()) {
|
| 926 |
+
throw new ZipException("actual and claimed size don't match"
|
| 927 |
+
+ USE_ZIPFILE_INSTEAD_OF_STREAM_DISCLAIMER);
|
| 928 |
+
}
|
| 929 |
+
lastStoredEntry = new ByteArrayInputStream(b);
|
| 930 |
+
}
|
| 931 |
+
|
| 932 |
+
private static final byte[] LFH = ZipLong.LFH_SIG.getBytes();
|
| 933 |
+
private static final byte[] CFH = ZipLong.CFH_SIG.getBytes();
|
| 934 |
+
private static final byte[] DD = ZipLong.DD_SIG.getBytes();
|
| 935 |
+
|
| 936 |
+
/**
|
| 937 |
+
* Checks whether the current buffer contains the signature of a
|
| 938 |
+
* "data descriptor", "local file header" or
|
| 939 |
+
* "central directory entry".
|
| 940 |
+
*
|
| 941 |
+
* <p>If it contains such a signature, reads the data descriptor
|
| 942 |
+
* and positions the stream right after the data descriptor.</p>
|
| 943 |
+
*/
|
| 944 |
+
private boolean bufferContainsSignature(final ByteArrayOutputStream bos, final int offset, final int lastRead, final int expectedDDLen)
|
| 945 |
+
throws IOException {
|
| 946 |
+
|
| 947 |
+
boolean done = false;
|
| 948 |
+
for (int i = 0; !done && i < offset + lastRead - 4; i++) {
|
| 949 |
+
if (buf.array()[i] == LFH[0] && buf.array()[i + 1] == LFH[1]) {
|
| 950 |
+
int expectDDPos = i;
|
| 951 |
+
if (i >= expectedDDLen &&
|
| 952 |
+
(buf.array()[i + 2] == LFH[2] && buf.array()[i + 3] == LFH[3])
|
| 953 |
+
|| (buf.array()[i] == CFH[2] && buf.array()[i + 3] == CFH[3])) {
|
| 954 |
+
// found a LFH or CFH:
|
| 955 |
+
expectDDPos = i - expectedDDLen;
|
| 956 |
+
done = true;
|
| 957 |
+
}
|
| 958 |
+
else if (buf.array()[i + 2] == DD[2] && buf.array()[i + 3] == DD[3]) {
|
| 959 |
+
// found DD:
|
| 960 |
+
done = true;
|
| 961 |
+
}
|
| 962 |
+
if (done) {
|
| 963 |
+
// * push back bytes read in excess as well as the data
|
| 964 |
+
// descriptor
|
| 965 |
+
// * copy the remaining bytes to cache
|
| 966 |
+
// * read data descriptor
|
| 967 |
+
pushback(buf.array(), expectDDPos, offset + lastRead - expectDDPos);
|
| 968 |
+
bos.write(buf.array(), 0, expectDDPos);
|
| 969 |
+
readDataDescriptor();
|
| 970 |
+
}
|
| 971 |
+
}
|
| 972 |
+
}
|
| 973 |
+
return done;
|
| 974 |
+
}
|
| 975 |
+
|
| 976 |
+
/**
|
| 977 |
+
* If the last read bytes could hold a data descriptor and an
|
| 978 |
+
* incomplete signature then save the last bytes to the front of
|
| 979 |
+
* the buffer and cache everything in front of the potential data
|
| 980 |
+
* descriptor into the given ByteArrayOutputStream.
|
| 981 |
+
*
|
| 982 |
+
* <p>Data descriptor plus incomplete signature (3 bytes in the
|
| 983 |
+
* worst case) can be 20 bytes max.</p>
|
| 984 |
+
*/
|
| 985 |
+
private int cacheBytesRead(final ByteArrayOutputStream bos, int offset, final int lastRead, final int expecteDDLen) {
|
| 986 |
+
final int cacheable = offset + lastRead - expecteDDLen - 3;
|
| 987 |
+
if (cacheable > 0) {
|
| 988 |
+
bos.write(buf.array(), 0, cacheable);
|
| 989 |
+
System.arraycopy(buf.array(), cacheable, buf.array(), 0, expecteDDLen + 3);
|
| 990 |
+
offset = expecteDDLen + 3;
|
| 991 |
+
} else {
|
| 992 |
+
offset += lastRead;
|
| 993 |
+
}
|
| 994 |
+
return offset;
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
private void pushback(final byte[] buf, final int offset, final int length) throws IOException {
|
| 998 |
+
((PushbackInputStream) in).unread(buf, offset, length);
|
| 999 |
+
pushedBackBytes(length);
|
| 1000 |
+
}
|
| 1001 |
+
|
| 1002 |
+
// End of Central Directory Record
|
| 1003 |
+
// end of central dir signature WORD
|
| 1004 |
+
// number of this disk SHORT
|
| 1005 |
+
// number of the disk with the
|
| 1006 |
+
// start of the central directory SHORT
|
| 1007 |
+
// total number of entries in the
|
| 1008 |
+
// central directory on this disk SHORT
|
| 1009 |
+
// total number of entries in
|
| 1010 |
+
// the central directory SHORT
|
| 1011 |
+
// size of the central directory WORD
|
| 1012 |
+
// offset of start of central
|
| 1013 |
+
// directory with respect to
|
| 1014 |
+
// the starting disk number WORD
|
| 1015 |
+
// .ZIP file comment length SHORT
|
| 1016 |
+
// .ZIP file comment up to 64KB
|
| 1017 |
+
//
|
| 1018 |
+
|
| 1019 |
+
/**
|
| 1020 |
+
* Reads the stream until it find the "End of central directory
|
| 1021 |
+
* record" and consumes it as well.
|
| 1022 |
+
*/
|
| 1023 |
+
private void skipRemainderOfArchive() throws IOException {
|
| 1024 |
+
// skip over central directory. One LFH has been read too much
|
| 1025 |
+
// already. The calculation discounts file names and extra
|
| 1026 |
+
// data so it will be too short.
|
| 1027 |
+
realSkip((long) entriesRead * CFH_LEN - LFH_LEN);
|
| 1028 |
+
findEocdRecord();
|
| 1029 |
+
realSkip((long) ZipFile.MIN_EOCD_SIZE - WORD /* signature */ - SHORT /* comment len */);
|
| 1030 |
+
readFully(shortBuf);
|
| 1031 |
+
// file comment
|
| 1032 |
+
realSkip(ZipShort.getValue(shortBuf));
|
| 1033 |
+
}
|
| 1034 |
+
|
| 1035 |
+
/**
|
| 1036 |
+
* Reads forward until the signature of the "End of central
|
| 1037 |
+
* directory" record is found.
|
| 1038 |
+
*/
|
| 1039 |
+
private void findEocdRecord() throws IOException {
|
| 1040 |
+
int currentByte = -1;
|
| 1041 |
+
boolean skipReadCall = false;
|
| 1042 |
+
while (skipReadCall || (currentByte = readOneByte()) > -1) {
|
| 1043 |
+
skipReadCall = false;
|
| 1044 |
+
if (!isFirstByteOfEocdSig(currentByte)) {
|
| 1045 |
+
continue;
|
| 1046 |
+
}
|
| 1047 |
+
currentByte = readOneByte();
|
| 1048 |
+
if (currentByte != ZipArchiveOutputStream.EOCD_SIG[1]) {
|
| 1049 |
+
if (currentByte == -1) {
|
| 1050 |
+
break;
|
| 1051 |
+
}
|
| 1052 |
+
skipReadCall = isFirstByteOfEocdSig(currentByte);
|
| 1053 |
+
continue;
|
| 1054 |
+
}
|
| 1055 |
+
currentByte = readOneByte();
|
| 1056 |
+
if (currentByte != ZipArchiveOutputStream.EOCD_SIG[2]) {
|
| 1057 |
+
if (currentByte == -1) {
|
| 1058 |
+
break;
|
| 1059 |
+
}
|
| 1060 |
+
skipReadCall = isFirstByteOfEocdSig(currentByte);
|
| 1061 |
+
continue;
|
| 1062 |
+
}
|
| 1063 |
+
currentByte = readOneByte();
|
| 1064 |
+
if (currentByte == -1
|
| 1065 |
+
|| currentByte == ZipArchiveOutputStream.EOCD_SIG[3]) {
|
| 1066 |
+
break;
|
| 1067 |
+
}
|
| 1068 |
+
skipReadCall = isFirstByteOfEocdSig(currentByte);
|
| 1069 |
+
}
|
| 1070 |
+
}
|
| 1071 |
+
|
| 1072 |
+
/**
|
| 1073 |
+
* Skips bytes by reading from the underlying stream rather than
|
| 1074 |
+
* the (potentially inflating) archive stream - which {@link
|
| 1075 |
+
* #skip} would do.
|
| 1076 |
+
*
|
| 1077 |
+
* Also updates bytes-read counter.
|
| 1078 |
+
*/
|
| 1079 |
+
private void realSkip(final long value) throws IOException {
|
| 1080 |
+
if (value >= 0) {
|
| 1081 |
+
long skipped = 0;
|
| 1082 |
+
while (skipped < value) {
|
| 1083 |
+
final long rem = value - skipped;
|
| 1084 |
+
final int x = in.read(skipBuf, 0, (int) (skipBuf.length > rem ? rem : skipBuf.length));
|
| 1085 |
+
if (x == -1) {
|
| 1086 |
+
return;
|
| 1087 |
+
}
|
| 1088 |
+
count(x);
|
| 1089 |
+
skipped += x;
|
| 1090 |
+
}
|
| 1091 |
+
return;
|
| 1092 |
+
}
|
| 1093 |
+
throw new IllegalArgumentException();
|
| 1094 |
+
}
|
| 1095 |
+
|
| 1096 |
+
/**
|
| 1097 |
+
* Reads bytes by reading from the underlying stream rather than
|
| 1098 |
+
* the (potentially inflating) archive stream - which {@link #read} would do.
|
| 1099 |
+
*
|
| 1100 |
+
* Also updates bytes-read counter.
|
| 1101 |
+
*/
|
| 1102 |
+
private int readOneByte() throws IOException {
|
| 1103 |
+
final int b = in.read();
|
| 1104 |
+
if (b != -1) {
|
| 1105 |
+
count(1);
|
| 1106 |
+
}
|
| 1107 |
+
return b;
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
private boolean isFirstByteOfEocdSig(final int b) {
|
| 1111 |
+
return b == ZipArchiveOutputStream.EOCD_SIG[0];
|
| 1112 |
+
}
|
| 1113 |
+
|
| 1114 |
+
private static final byte[] APK_SIGNING_BLOCK_MAGIC = new byte[] {
|
| 1115 |
+
'A', 'P', 'K', ' ', 'S', 'i', 'g', ' ', 'B', 'l', 'o', 'c', 'k', ' ', '4', '2',
|
| 1116 |
+
};
|
| 1117 |
+
private static final BigInteger LONG_MAX = BigInteger.valueOf(Long.MAX_VALUE);
|
| 1118 |
+
|
| 1119 |
+
/**
|
| 1120 |
+
* Checks whether this might be an APK Signing Block.
|
| 1121 |
+
*
|
| 1122 |
+
* <p>Unfortunately the APK signing block does not start with some kind of signature, it rather ends with one. It
|
| 1123 |
+
* starts with a length, so what we do is parse the suspect length, skip ahead far enough, look for the signature
|
| 1124 |
+
* and if we've found it, return true.</p>
|
| 1125 |
+
*
|
| 1126 |
+
* @param suspectLocalFileHeader the bytes read from the underlying stream in the expectation that they would hold
|
| 1127 |
+
* the local file header of the next entry.
|
| 1128 |
+
*
|
| 1129 |
+
* @return true if this looks like a APK signing block
|
| 1130 |
+
*
|
| 1131 |
+
* @see <a href="https://source.android.com/security/apksigning/v2">https://source.android.com/security/apksigning/v2</a>
|
| 1132 |
+
*/
|
| 1133 |
+
private boolean isApkSigningBlock(byte[] suspectLocalFileHeader) throws IOException {
|
| 1134 |
+
// length of block excluding the size field itself
|
| 1135 |
+
BigInteger len = ZipEightByteInteger.getValue(suspectLocalFileHeader);
|
| 1136 |
+
// LFH has already been read and all but the first eight bytes contain (part of) the APK signing block,
|
| 1137 |
+
// also subtract 16 bytes in order to position us at the magic string
|
| 1138 |
+
BigInteger toSkip = len.add(BigInteger.valueOf(DWORD - suspectLocalFileHeader.length
|
| 1139 |
+
- (long) APK_SIGNING_BLOCK_MAGIC.length));
|
| 1140 |
+
byte[] magic = new byte[APK_SIGNING_BLOCK_MAGIC.length];
|
| 1141 |
+
|
| 1142 |
+
try {
|
| 1143 |
+
if (toSkip.signum() < 0) {
|
| 1144 |
+
// suspectLocalFileHeader contains the start of suspect magic string
|
| 1145 |
+
int off = suspectLocalFileHeader.length + toSkip.intValue();
|
| 1146 |
+
// length was shorter than magic length
|
| 1147 |
+
if (off < DWORD) {
|
| 1148 |
+
return false;
|
| 1149 |
+
}
|
| 1150 |
+
int bytesInBuffer = Math.abs(toSkip.intValue());
|
| 1151 |
+
System.arraycopy(suspectLocalFileHeader, off, magic, 0, Math.min(bytesInBuffer, magic.length));
|
| 1152 |
+
if (bytesInBuffer < magic.length) {
|
| 1153 |
+
readFully(magic, bytesInBuffer);
|
| 1154 |
+
}
|
| 1155 |
+
} else {
|
| 1156 |
+
while (toSkip.compareTo(LONG_MAX) > 0) {
|
| 1157 |
+
realSkip(Long.MAX_VALUE);
|
| 1158 |
+
toSkip = toSkip.add(LONG_MAX.negate());
|
| 1159 |
+
}
|
| 1160 |
+
realSkip(toSkip.longValue());
|
| 1161 |
+
readFully(magic);
|
| 1162 |
+
}
|
| 1163 |
+
} catch (EOFException ex) { //NOSONAR
|
| 1164 |
+
// length was invalid
|
| 1165 |
+
return false;
|
| 1166 |
+
}
|
| 1167 |
+
return Arrays.equals(magic, APK_SIGNING_BLOCK_MAGIC);
|
| 1168 |
+
}
|
| 1169 |
+
|
| 1170 |
+
/**
|
| 1171 |
+
* Structure collecting information for the entry that is
|
| 1172 |
+
* currently being read.
|
| 1173 |
+
*/
|
| 1174 |
+
private static final class CurrentEntry {
|
| 1175 |
+
|
| 1176 |
+
/**
|
| 1177 |
+
* Current ZIP entry.
|
| 1178 |
+
*/
|
| 1179 |
+
private final ZipArchiveEntry entry = new ZipArchiveEntry();
|
| 1180 |
+
|
| 1181 |
+
/**
|
| 1182 |
+
* Does the entry use a data descriptor?
|
| 1183 |
+
*/
|
| 1184 |
+
private boolean hasDataDescriptor;
|
| 1185 |
+
|
| 1186 |
+
/**
|
| 1187 |
+
* Does the entry have a ZIP64 extended information extra field.
|
| 1188 |
+
*/
|
| 1189 |
+
private boolean usesZip64;
|
| 1190 |
+
|
| 1191 |
+
/**
|
| 1192 |
+
* Number of bytes of entry content read by the client if the
|
| 1193 |
+
* entry is STORED.
|
| 1194 |
+
*/
|
| 1195 |
+
private long bytesRead;
|
| 1196 |
+
|
| 1197 |
+
/**
|
| 1198 |
+
* Number of bytes of entry content read from the stream.
|
| 1199 |
+
*
|
| 1200 |
+
* <p>This may be more than the actual entry's length as some
|
| 1201 |
+
* stuff gets buffered up and needs to be pushed back when the
|
| 1202 |
+
* end of the entry has been reached.</p>
|
| 1203 |
+
*/
|
| 1204 |
+
private long bytesReadFromStream;
|
| 1205 |
+
|
| 1206 |
+
/**
|
| 1207 |
+
* The checksum calculated as the current entry is read.
|
| 1208 |
+
*/
|
| 1209 |
+
private final CRC32 crc = new CRC32();
|
| 1210 |
+
|
| 1211 |
+
/**
|
| 1212 |
+
* The input stream decompressing the data for shrunk and imploded entries.
|
| 1213 |
+
*/
|
| 1214 |
+
private InputStream in;
|
| 1215 |
+
}
|
| 1216 |
+
|
| 1217 |
+
/**
|
| 1218 |
+
* Bounded input stream adapted from commons-io
|
| 1219 |
+
*/
|
| 1220 |
+
private class BoundedInputStream extends InputStream {
|
| 1221 |
+
|
| 1222 |
+
/** the wrapped input stream */
|
| 1223 |
+
private final InputStream in;
|
| 1224 |
+
|
| 1225 |
+
/** the max length to provide */
|
| 1226 |
+
private final long max;
|
| 1227 |
+
|
| 1228 |
+
/** the number of bytes already returned */
|
| 1229 |
+
private long pos = 0;
|
| 1230 |
+
|
| 1231 |
+
/**
|
| 1232 |
+
* Creates a new <code>BoundedInputStream</code> that wraps the given input
|
| 1233 |
+
* stream and limits it to a certain size.
|
| 1234 |
+
*
|
| 1235 |
+
* @param in The wrapped input stream
|
| 1236 |
+
* @param size The maximum number of bytes to return
|
| 1237 |
+
*/
|
| 1238 |
+
public BoundedInputStream(final InputStream in, final long size) {
|
| 1239 |
+
this.max = size;
|
| 1240 |
+
this.in = in;
|
| 1241 |
+
}
|
| 1242 |
+
|
| 1243 |
+
@Override
|
| 1244 |
+
public int read() throws IOException {
|
| 1245 |
+
if (max >= 0 && pos >= max) {
|
| 1246 |
+
return -1;
|
| 1247 |
+
}
|
| 1248 |
+
final int result = in.read();
|
| 1249 |
+
pos++;
|
| 1250 |
+
count(1);
|
| 1251 |
+
current.bytesReadFromStream++;
|
| 1252 |
+
return result;
|
| 1253 |
+
}
|
| 1254 |
+
|
| 1255 |
+
@Override
|
| 1256 |
+
public int read(final byte[] b) throws IOException {
|
| 1257 |
+
return this.read(b, 0, b.length);
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
@Override
|
| 1261 |
+
public int read(final byte[] b, final int off, final int len) throws IOException {
|
| 1262 |
+
if (len == 0) {
|
| 1263 |
+
return 0;
|
| 1264 |
+
}
|
| 1265 |
+
if (max >= 0 && pos >= max) {
|
| 1266 |
+
return -1;
|
| 1267 |
+
}
|
| 1268 |
+
final long maxRead = max >= 0 ? Math.min(len, max - pos) : len;
|
| 1269 |
+
final int bytesRead = in.read(b, off, (int) maxRead);
|
| 1270 |
+
|
| 1271 |
+
if (bytesRead == -1) {
|
| 1272 |
+
return -1;
|
| 1273 |
+
}
|
| 1274 |
+
|
| 1275 |
+
pos += bytesRead;
|
| 1276 |
+
count(bytesRead);
|
| 1277 |
+
current.bytesReadFromStream += bytesRead;
|
| 1278 |
+
return bytesRead;
|
| 1279 |
+
}
|
| 1280 |
+
|
| 1281 |
+
@Override
|
| 1282 |
+
public long skip(final long n) throws IOException {
|
| 1283 |
+
final long toSkip = max >= 0 ? Math.min(n, max - pos) : n;
|
| 1284 |
+
final long skippedBytes = IOUtils.skip(in, toSkip);
|
| 1285 |
+
pos += skippedBytes;
|
| 1286 |
+
return skippedBytes;
|
| 1287 |
+
}
|
| 1288 |
+
|
| 1289 |
+
@Override
|
| 1290 |
+
public int available() throws IOException {
|
| 1291 |
+
if (max >= 0 && pos >= max) {
|
| 1292 |
+
return 0;
|
| 1293 |
+
}
|
| 1294 |
+
return in.available();
|
| 1295 |
+
}
|
| 1296 |
+
}
|
| 1297 |
+
}
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/file_to_compare_1
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 3 |
+
* or more contributor license agreements. See the NOTICE file
|
| 4 |
+
* distributed with this work for additional information
|
| 5 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 6 |
+
* to you under the Apache License, Version 2.0 (the
|
| 7 |
+
* "License"); you may not use this file except in compliance
|
| 8 |
+
* with the License. You may obtain a copy of the License at
|
| 9 |
+
*
|
| 10 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
*
|
| 12 |
+
* Unless required by applicable law or agreed to in writing,
|
| 13 |
+
* software distributed under the License is distributed on an
|
| 14 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 15 |
+
* KIND, either express or implied. See the License for the
|
| 16 |
+
* specific language governing permissions and limitations
|
| 17 |
+
* under the License.
|
| 18 |
+
*/
|
| 19 |
+
package org.apache.commons.compress.archivers.dump;
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Unsupported compression algorithm. The dump archive uses an unsupported
|
| 24 |
+
* compression algorithm (BZLIB2 or LZO).
|
| 25 |
+
*/
|
| 26 |
+
public class UnsupportedCompressionAlgorithmException
|
| 27 |
+
extends DumpArchiveException {
|
| 28 |
+
private static final long serialVersionUID = 1L;
|
| 29 |
+
|
| 30 |
+
public UnsupportedCompressionAlgorithmException() {
|
| 31 |
+
super("this file uses an unsupported compression algorithm.");
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
public UnsupportedCompressionAlgorithmException(final String alg) {
|
| 35 |
+
super("this file uses an unsupported compression algorithm: " + alg +
|
| 36 |
+
".");
|
| 37 |
+
}
|
| 38 |
+
}
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/file_to_compare_2
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 3 |
+
* or more contributor license agreements. See the NOTICE file
|
| 4 |
+
* distributed with this work for additional information
|
| 5 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 6 |
+
* to you under the Apache License, Version 2.0 (the
|
| 7 |
+
* "License"); you may not use this file except in compliance
|
| 8 |
+
* with the License. You may obtain a copy of the License at
|
| 9 |
+
*
|
| 10 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
*
|
| 12 |
+
* Unless required by applicable law or agreed to in writing,
|
| 13 |
+
* software distributed under the License is distributed on an
|
| 14 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 15 |
+
* KIND, either express or implied. See the License for the
|
| 16 |
+
* specific language governing permissions and limitations
|
| 17 |
+
* under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
package org.apache.commons.compress.compressors.deflate;
|
| 21 |
+
|
| 22 |
+
import java.util.zip.Deflater;
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Parameters for the Deflate compressor.
|
| 26 |
+
* @since 1.9
|
| 27 |
+
*/
|
| 28 |
+
public class DeflateParameters {
|
| 29 |
+
|
| 30 |
+
private boolean zlibHeader = true;
|
| 31 |
+
private int compressionLevel = Deflater.DEFAULT_COMPRESSION;
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Whether or not the zlib header shall be written (when
|
| 35 |
+
* compressing) or expected (when decompressing).
|
| 36 |
+
* @return true if zlib header shall be written
|
| 37 |
+
*/
|
| 38 |
+
public boolean withZlibHeader() {
|
| 39 |
+
return zlibHeader;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Sets the zlib header presence parameter.
|
| 44 |
+
*
|
| 45 |
+
* <p>This affects whether or not the zlib header will be written
|
| 46 |
+
* (when compressing) or expected (when decompressing).</p>
|
| 47 |
+
*
|
| 48 |
+
* @param zlibHeader true if zlib header shall be written
|
| 49 |
+
*/
|
| 50 |
+
public void setWithZlibHeader(final boolean zlibHeader) {
|
| 51 |
+
this.zlibHeader = zlibHeader;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* The compression level.
|
| 56 |
+
* @see #setCompressionLevel
|
| 57 |
+
* @return the compression level
|
| 58 |
+
*/
|
| 59 |
+
public int getCompressionLevel() {
|
| 60 |
+
return compressionLevel;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* Sets the compression level.
|
| 65 |
+
*
|
| 66 |
+
* @param compressionLevel the compression level (between 0 and 9)
|
| 67 |
+
* @see Deflater#NO_COMPRESSION
|
| 68 |
+
* @see Deflater#BEST_SPEED
|
| 69 |
+
* @see Deflater#DEFAULT_COMPRESSION
|
| 70 |
+
* @see Deflater#BEST_COMPRESSION
|
| 71 |
+
*/
|
| 72 |
+
public void setCompressionLevel(final int compressionLevel) {
|
| 73 |
+
if (compressionLevel < -1 || compressionLevel > 9) {
|
| 74 |
+
throw new IllegalArgumentException("Invalid Deflate compression level: " + compressionLevel);
|
| 75 |
+
}
|
| 76 |
+
this.compressionLevel = compressionLevel;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
}
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/META-INF/services/org.apache.commons.compress.compressors.CompressorStreamProvider
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
org.apache.commons.compress.compressors.TestCompressorStreamProvider
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/COMPRESS-644/ARW05UP.ICO
ADDED
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/COMPRESS-649/some-900kb-text.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/COMPRESS-661/testARofText.ar
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!<arch>
|
| 2 |
+
testTXT.txt/ 1262968202 500 500 100644 47 `
|
| 3 |
+
Test d'indexation de Txt
|
| 4 |
+
http://www.apache.org
|
| 5 |
+
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_group-fail.ar
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!<arch>
|
| 2 |
+
// 68 `
|
| 3 |
+
this_is_a_long_file_name.txt/
|
| 4 |
+
this_is_a_long_file_name_as_well.txt/
|
| 5 |
+
/0 1454693980 1000 1.23 100664 14 `
|
| 6 |
+
Hello, world!
|
| 7 |
+
/30 1454694016 1000 1000 100664 4 `
|
| 8 |
+
Bye
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_length-fail.ar
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!<arch>
|
| 2 |
+
// 68 `
|
| 3 |
+
this_is_a_long_file_name.txt/
|
| 4 |
+
this_is_a_long_file_name_as_well.txt/
|
| 5 |
+
/0 1454693980 1000 1000 100664 1.23 `
|
| 6 |
+
Hello, world!
|
| 7 |
+
/30 1454694016 1000 1000 100664 4 `
|
| 8 |
+
Bye
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_long_namelen_bsd-fail.ar
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!<arch>
|
| 2 |
+
#1/123456789012 1311256511 1000 1000 100644 42 `
|
| 3 |
+
this_is_a_long_file_name.txtHello, world!
|
| 4 |
+
#1/36 1454694016 1000 1000 100664 40 `
|
| 5 |
+
this_is_a_long_file_name_as_well.txtBye
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_long_namelen_gnu1-fail.ar
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!<arch>
|
| 2 |
+
// 68 `
|
| 3 |
+
this_is_a_long_file_name.txt/
|
| 4 |
+
this_is_a_long_file_name_as_well.txt/
|
| 5 |
+
/9999999999 1454693980 1000 1000 100664 14 `
|
| 6 |
+
Hello, world!
|
| 7 |
+
/30 1454694016 1000 1000 100664 4 `
|
| 8 |
+
Bye
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_long_namelen_gnu2-fail.ar
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!<arch>
|
| 2 |
+
// 68 `
|
| 3 |
+
this_is_a_long_file_name.txt/
|
| 4 |
+
this_is_a_long_file_name_as_well.txt/
|
| 5 |
+
/29 1454694016 1000 1000 100664 4 `
|
| 6 |
+
Bye
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_long_namelen_gnu3-fail.ar
ADDED
|
Binary file (274 Bytes). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_modified-fail.ar
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!<arch>
|
| 2 |
+
// 68 `
|
| 3 |
+
this_is_a_long_file_name.txt/
|
| 4 |
+
this_is_a_long_file_name_as_well.txt/
|
| 5 |
+
/0 9e99999999 1000 1000 100664 14 `
|
| 6 |
+
Hello, world!
|
| 7 |
+
/30 1454694016 1000 1000 100664 4 `
|
| 8 |
+
Bye
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_table_length_gnu-fail.ar
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!<arch>
|
| 2 |
+
// 1.23 `
|
| 3 |
+
this_is_a_long_file_name.txt/
|
| 4 |
+
this_is_a_long_file_name_as_well.txt/
|
| 5 |
+
/0 1454693980 1000 1000 100664 14 `
|
| 6 |
+
Hello, world!
|
| 7 |
+
/30 1454694016 1000 1000 100664 4 `
|
| 8 |
+
Bye
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ar/number_parsing/bad_user-fail.ar
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!<arch>
|
| 2 |
+
// 68 `
|
| 3 |
+
this_is_a_long_file_name.txt/
|
| 4 |
+
this_is_a_long_file_name_as_well.txt/
|
| 5 |
+
/0 1454693980 9e99 1000 100664 14 `
|
| 6 |
+
Hello, world!
|
| 7 |
+
/30 1454694016 1000 1000 100664 4 `
|
| 8 |
+
Bye
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/arj/zero_sized_headers-fail.arj
ADDED
|
Binary file (3.14 kB). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/cpio/bad_long_value.cpio
ADDED
|
Binary file (1.54 kB). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/dump/directory_null_bytes-fail.dump
ADDED
|
Binary file (78.9 kB). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/dump/invalid_compression_type-fail.dump
ADDED
|
Binary file (11.9 kB). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/dump/looping_inodes-fail.dump
ADDED
|
Binary file (85.2 kB). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/dump/reclen_zero-fail.dump
ADDED
|
Binary file (85.8 kB). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/fuzz/crash-f2efd9eaeb86cda597d07b5e3c3d81363633c2da
ADDED
|
Binary file (8.94 kB). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ico/commons-daemon/procrunr.ico
ADDED
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ico/commons-daemon/procruns.ico
ADDED
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ico/commons-daemon/procrunw.ico
ADDED
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/ico/commons-imaging/OutOfMemory_epine.ico
ADDED
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/bandint_oom.pack
ADDED
|
Binary file (88 Bytes). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/cpfloat_oom.pack
ADDED
|
Binary file (178 Bytes). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/cputf8_oom.pack
ADDED
|
Binary file (427 Bytes). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/favoured_oom.pack
ADDED
|
Binary file (84 Bytes). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/filebits_oom.pack
ADDED
|
Binary file (309 Bytes). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/flags_oom.pack
ADDED
|
Binary file (1.62 kB). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/references_oom.pack
ADDED
|
Binary file (66 Bytes). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/segment_header_oom.pack
ADDED
|
Binary file (41 Bytes). View file
|
|
|
local-test-commons-compress-delta-03/afc-commons-compress/src/test/resources/org/apache/commons/compress/pack/signatures_oom.pack
ADDED
|
Binary file (121 Bytes). View file
|
|
|
local-test-commons-compress-delta-03/fuzz-tooling/docs/assets/css/just-the-docs-wider.scss
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
---
|
| 3 |
+
{% include css/just-the-docs.scss.liquid color_scheme="wider" %}
|
local-test-commons-compress-delta-03/fuzz-tooling/docs/getting-started/new-project-guide/swift_lang.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
layout: default
|
| 3 |
+
title: Integrating a Swift project
|
| 4 |
+
parent: Setting up a new project
|
| 5 |
+
grand_parent: Getting started
|
| 6 |
+
nav_order: 1
|
| 7 |
+
permalink: /getting-started/new-project-guide/swift-lang/
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Integrating a Swift project
|
| 11 |
+
{: .no_toc}
|
| 12 |
+
|
| 13 |
+
- TOC
|
| 14 |
+
{:toc}
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
The process of integrating a project written in Swift with OSS-Fuzz is very similar
|
| 18 |
+
to the general
|
| 19 |
+
[Setting up a new project]({{ site.baseurl }}/getting-started/new-project-guide/)
|
| 20 |
+
process. The key specifics of integrating a Swift project are outlined below.
|
| 21 |
+
|
| 22 |
+
## Project files
|
| 23 |
+
|
| 24 |
+
First, you need to write a Swift fuzz target that accepts a stream of bytes and
|
| 25 |
+
calls the program API with that. This fuzz target should reside in your project
|
| 26 |
+
repository.
|
| 27 |
+
|
| 28 |
+
The structure of the project directory in OSS-Fuzz repository doesn't differ for
|
| 29 |
+
projects written in Swift. The project files have the following Swift specific
|
| 30 |
+
aspects.
|
| 31 |
+
|
| 32 |
+
### project.yaml
|
| 33 |
+
|
| 34 |
+
The `language` attribute must be specified.
|
| 35 |
+
|
| 36 |
+
```yaml
|
| 37 |
+
language: swift
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
The only supported fuzzing engine is `libfuzzer`
|
| 41 |
+
|
| 42 |
+
The supported sanitizers are and `address`, `thread`
|
| 43 |
+
|
| 44 |
+
[Example](https://github.com/google/oss-fuzz/blob/2a15c3c88b21f4f1be2a7ff115f72bd7a08e34ac/projects/swift-nio/project.yaml#L9):
|
| 45 |
+
|
| 46 |
+
```yaml
|
| 47 |
+
fuzzing_engines:
|
| 48 |
+
- libfuzzer
|
| 49 |
+
sanitizers:
|
| 50 |
+
- address
|
| 51 |
+
- thread
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### Dockerfile
|
| 55 |
+
|
| 56 |
+
The Dockerfile should start by `FROM gcr.io/oss-fuzz-base/base-builder-swift`
|
| 57 |
+
instead of using the simple base-builder
|
| 58 |
+
|
| 59 |
+
### build.sh
|
| 60 |
+
|
| 61 |
+
A `precompile_swift` generates an environment variable `SWIFTFLAGS`
|
| 62 |
+
This can then be used in the building command such as `swift build -c release $SWIFTFLAGS`
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
A usage example from swift-protobuf project is
|
| 66 |
+
|
| 67 |
+
```sh
|
| 68 |
+
. precompile_swift
|
| 69 |
+
# build project
|
| 70 |
+
cd FuzzTesting
|
| 71 |
+
swift build -c debug $SWIFTFLAGS
|
| 72 |
+
|
| 73 |
+
(
|
| 74 |
+
cd .build/debug/
|
| 75 |
+
find . -maxdepth 1 -type f -name "*Fuzzer" -executable | while read i; do cp $i $OUT/"$i"-debug; done
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
```
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/.vscodeignore
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.vscode/**
|
| 2 |
+
.vscode-test/**
|
| 3 |
+
src/**
|
| 4 |
+
.gitignore
|
| 5 |
+
.yarnrc
|
| 6 |
+
vsc-extension-quickstart.md
|
| 7 |
+
**/tsconfig.json
|
| 8 |
+
**/.eslintrc.json
|
| 9 |
+
**/*.map
|
| 10 |
+
**/*.ts
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# OSS-Fuzz VSCode extension
|
| 2 |
+
|
| 3 |
+
[OSS-Fuzz](https://github.com/google/oss-fuzz) is a fuzzing toolkit and service for fuzzing open source projects. This VSCode extension provides features and capabilities for interacting with the OSS-Fuzz toolkit and also to compare local changes to the OSS-Fuzz cloud database by way of [Open source fuzz introspection](https://introspector.oss-fuzz.com).
|
| 4 |
+
|
| 5 |
+
## Features
|
| 6 |
+
|
| 7 |
+
The VSCode extension is largely driven by commands at this point. The featues of these commands includes:
|
| 8 |
+
|
| 9 |
+
- Easily setting up OSS-Fuzz
|
| 10 |
+
- Templates for easily setting up a new OSS-Fuzz project
|
| 11 |
+
- Building arbitrary projects from OSS-Fuzz
|
| 12 |
+
- Modify a project from VSCode and test changes in OSS-Fuzz
|
| 13 |
+
- Easily extract code coverage of fuzzers, including local-only fuzzers
|
| 14 |
+
- Compare local code coverage to what is currently achieved by OSS-Fuzz
|
| 15 |
+
- Auto-generation of fuzzer templates
|
| 16 |
+
|
| 17 |
+
For a full list of commands and their features, please check the commands page.
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commandUtils.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
export const commandHistory: any[] = [];
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspace.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
import {println} from '../logger';
|
| 19 |
+
import {commandHistory} from '../commandUtils';
|
| 20 |
+
import {
|
| 21 |
+
hasOssFuzzInWorkspace,
|
| 22 |
+
getOssFuzzWorkspaceProjectName,
|
| 23 |
+
setStatusText,
|
| 24 |
+
} from '../utils';
|
| 25 |
+
import {buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
|
| 26 |
+
|
| 27 |
+
export async function cmdInputCollectorBuildFuzzersFromWorkspace() {
|
| 28 |
+
let ossFuzzProjectName = '';
|
| 29 |
+
// First determine if we have a name in the workspace
|
| 30 |
+
if (await hasOssFuzzInWorkspace()) {
|
| 31 |
+
/**
|
| 32 |
+
* The fuzzers are in the workspace, as opposed to e.g. the oss-fuzz dirctory.
|
| 33 |
+
*/
|
| 34 |
+
ossFuzzProjectName = await getOssFuzzWorkspaceProjectName();
|
| 35 |
+
} else {
|
| 36 |
+
// If we did not have that, ask the user.
|
| 37 |
+
|
| 38 |
+
const ossFuzzProjectNameInput = await vscode.window.showInputBox({
|
| 39 |
+
value: '',
|
| 40 |
+
placeHolder: 'The OSS-Fuzz project name',
|
| 41 |
+
});
|
| 42 |
+
if (!ossFuzzProjectNameInput) {
|
| 43 |
+
println('Did not get a ossFuzzTargetProject');
|
| 44 |
+
return false;
|
| 45 |
+
}
|
| 46 |
+
ossFuzzProjectName = ossFuzzProjectNameInput.toString();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// Create an history object
|
| 50 |
+
const args = new Object({
|
| 51 |
+
projectName: ossFuzzProjectName,
|
| 52 |
+
sanitizer: '',
|
| 53 |
+
toClean: false,
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
const commandObject = new Object({
|
| 57 |
+
commandType: 'oss-fuzz.WSBuildFuzzers',
|
| 58 |
+
Arguments: args,
|
| 59 |
+
dispatcherFunc: cmdDispatchBuildFuzzersFromWorkspace,
|
| 60 |
+
});
|
| 61 |
+
console.log('L1: ' + commandHistory.length);
|
| 62 |
+
commandHistory.push(commandObject);
|
| 63 |
+
|
| 64 |
+
await cmdDispatchBuildFuzzersFromWorkspace(args);
|
| 65 |
+
return true;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
async function cmdDispatchBuildFuzzersFromWorkspace(args: any) {
|
| 69 |
+
await setStatusText('Building fuzzers: starting');
|
| 70 |
+
const res = await buildFuzzersFromWorkspace(
|
| 71 |
+
args.projectName,
|
| 72 |
+
args.sanitizer,
|
| 73 |
+
args.toClean
|
| 74 |
+
);
|
| 75 |
+
if (res) {
|
| 76 |
+
await setStatusText('Building fuzzers: finished');
|
| 77 |
+
} else {
|
| 78 |
+
await setStatusText('Building fuzzers: failed');
|
| 79 |
+
}
|
| 80 |
+
}
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdCreateOSSFuzzSetup.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import {setupProjectInitialFiles} from '../projectIntegrationHelper';
|
| 18 |
+
import {setStatusText} from '../utils';
|
| 19 |
+
|
| 20 |
+
export async function createOssFuzzSetup() {
|
| 21 |
+
await setStatusText('Creating OSS-Fuzz setup: starting');
|
| 22 |
+
const res = await setupProjectInitialFiles(false);
|
| 23 |
+
if (res) {
|
| 24 |
+
await setStatusText('Creating OSS-Fuzz setup: finished');
|
| 25 |
+
} else {
|
| 26 |
+
await setStatusText('Creating OSS-Fuzz setup: failed');
|
| 27 |
+
}
|
| 28 |
+
}
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdFIGetOptimalTargets.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2025 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import {getOptimalTargetsFromIntrospector} from '../fuzzIntrospectorHelper';
|
| 18 |
+
|
| 19 |
+
export async function runGetOptimalTargetsHandler() {
|
| 20 |
+
getOptimalTargetsFromIntrospector();
|
| 21 |
+
}
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdReproduceTestcase.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
const fs = require('fs');
|
| 19 |
+
import {println} from '../logger';
|
| 20 |
+
import {commandHistory} from '../commandUtils';
|
| 21 |
+
import {systemSyncLogIfFailure} from '../utils';
|
| 22 |
+
import {buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
|
| 23 |
+
import {extensionConfig} from '../config';
|
| 24 |
+
const readline = require('readline');
|
| 25 |
+
|
| 26 |
+
export async function cmdInputCollectorReproduceTestcase() {
|
| 27 |
+
// Runs a fuzzer from a given project.
|
| 28 |
+
const crashFileInput = await vscode.window.showInputBox({
|
| 29 |
+
value: '',
|
| 30 |
+
placeHolder: 'The ID of the testcase.',
|
| 31 |
+
});
|
| 32 |
+
if (!crashFileInput) {
|
| 33 |
+
return;
|
| 34 |
+
}
|
| 35 |
+
// Create an history object and append it to the command history.
|
| 36 |
+
const args = new Object({
|
| 37 |
+
crashFile: crashFileInput.toString(),
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
const commandObject = new Object({
|
| 41 |
+
commandType: 'oss-fuzz.ReproduceFuzzer',
|
| 42 |
+
Arguments: args,
|
| 43 |
+
dispatcherFunc: cmdDispatchReproduceTestcase,
|
| 44 |
+
});
|
| 45 |
+
commandHistory.push(commandObject);
|
| 46 |
+
|
| 47 |
+
await cmdDispatchReproduceTestcase(args);
|
| 48 |
+
return true;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
async function cmdDispatchReproduceTestcase(args: any) {
|
| 52 |
+
await reproduceTestcase(args.crashFile);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
export async function reproduceTestcase(crashInfoFileInput: string) {
|
| 56 |
+
println('Reproducing testcase for ' + crashInfoFileInput);
|
| 57 |
+
println('Checking directory: ' + extensionConfig.crashesDirectory);
|
| 58 |
+
|
| 59 |
+
const crashInfoFile =
|
| 60 |
+
extensionConfig.crashesDirectory + '/' + crashInfoFileInput + '.info';
|
| 61 |
+
println(crashInfoFile);
|
| 62 |
+
try {
|
| 63 |
+
if (fs.existsSync(crashInfoFile)) {
|
| 64 |
+
println('File exists');
|
| 65 |
+
} else {
|
| 66 |
+
println('Crash file does not exist');
|
| 67 |
+
return;
|
| 68 |
+
}
|
| 69 |
+
} catch (err) {
|
| 70 |
+
console.error(err);
|
| 71 |
+
return;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// At this point the file exists
|
| 75 |
+
const r = readline.createInterface({
|
| 76 |
+
input: fs.createReadStream(crashInfoFile),
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
let targetProject = 'N/A';
|
| 80 |
+
let targetFuzzer = 'N/A';
|
| 81 |
+
// Logic for passing the file. This is based off of clusterfuzz monorail reports,
|
| 82 |
+
// and the intention is the file needs to be a copy of:
|
| 83 |
+
//
|
| 84 |
+
// Project: project-name
|
| 85 |
+
// Fuzzing Engine: libFuzzer
|
| 86 |
+
// Fuzz Target: fuzzer-name
|
| 87 |
+
//
|
| 88 |
+
// Example:
|
| 89 |
+
// The following URL: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59747
|
| 90 |
+
// has the bug information:
|
| 91 |
+
// """
|
| 92 |
+
// Project: my-fuzzing-project
|
| 93 |
+
// Fuzzing Engine: libFuzzer
|
| 94 |
+
// Fuzz Target: the-fuzzer-name-fuzz-parseXX
|
| 95 |
+
// Job Type: libfuzzer_asan_my-fuzzing-project
|
| 96 |
+
// Platform Id: linux
|
| 97 |
+
// """
|
| 98 |
+
// and a link to a reproducer test case:
|
| 99 |
+
// https://oss-fuzz.com/download?testcase_id=5009071179431936
|
| 100 |
+
// which, when accessed will download the file
|
| 101 |
+
// clusterfuzz-testcase-minimized-flb-it-fuzz-config_map_fuzzer_OSSFUZZ-5009071179431936
|
| 102 |
+
//
|
| 103 |
+
// To enable reproducing of this issue we need to:
|
| 104 |
+
// - 1) Download the crash file and place it in the directory given in config.ts
|
| 105 |
+
// and "crashesDirectory" variable.
|
| 106 |
+
// - 2) create a file "5009071179431936.info" and paste the information above
|
| 107 |
+
// (Project:... Fuzz Target: ...) into the file. This information is
|
| 108 |
+
// needed because we need to know project name and fuzzer name in order
|
| 109 |
+
// to reproduce the crash.
|
| 110 |
+
// - 3) the reproducer can now be reproduced using the reproduce command
|
| 111 |
+
// with argument "5009071179431936" as argument.
|
| 112 |
+
r.on('line', (text: string) => {
|
| 113 |
+
println(text);
|
| 114 |
+
if (text.startsWith('Project: ')) {
|
| 115 |
+
println('Starts with project');
|
| 116 |
+
println(text.split('Project: ').toString());
|
| 117 |
+
targetProject = text.split('Project: ')[1];
|
| 118 |
+
} else if (text.startsWith('Fuzzing Engine: ')) {
|
| 119 |
+
println('Starts with fuzzing engine');
|
| 120 |
+
} else if (text.startsWith('Fuzz Target:')) {
|
| 121 |
+
println('Starts with Fuzz Target');
|
| 122 |
+
targetFuzzer = text.split('Fuzz Target: ')[1];
|
| 123 |
+
} else if (text.startsWith('Job Type:')) {
|
| 124 |
+
println('Starts with Job Type');
|
| 125 |
+
}
|
| 126 |
+
});
|
| 127 |
+
|
| 128 |
+
r.on('close', async () => {
|
| 129 |
+
println('Target project: ' + targetProject);
|
| 130 |
+
println('Target fuzzer: ' + targetFuzzer);
|
| 131 |
+
|
| 132 |
+
// Build a fresh version of the project.
|
| 133 |
+
const buildResult: boolean = await buildFuzzersFromWorkspace(
|
| 134 |
+
targetProject,
|
| 135 |
+
'',
|
| 136 |
+
true
|
| 137 |
+
);
|
| 138 |
+
if (!buildResult) {
|
| 139 |
+
println('Failed to build fuzzers');
|
| 140 |
+
return false;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
// We have a fresh build of the project, proceed to reproduce the testcase.
|
| 144 |
+
const crashInputTestCase =
|
| 145 |
+
extensionConfig.crashesDirectory +
|
| 146 |
+
'/' +
|
| 147 |
+
'clusterfuzz-testcase-minimized-' +
|
| 148 |
+
targetFuzzer +
|
| 149 |
+
'-' +
|
| 150 |
+
crashInfoFileInput;
|
| 151 |
+
// Run reproduce command against the target file
|
| 152 |
+
// Build the fuzzers using OSS-Fuzz infrastructure.
|
| 153 |
+
const cmdToExec = 'python3';
|
| 154 |
+
const args = [
|
| 155 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 156 |
+
'reproduce',
|
| 157 |
+
targetProject,
|
| 158 |
+
targetFuzzer,
|
| 159 |
+
crashInputTestCase,
|
| 160 |
+
];
|
| 161 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 162 |
+
println('Failed to reproduce testcase');
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
return true;
|
| 166 |
+
});
|
| 167 |
+
}
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupOSSFuzz.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import {println} from '../logger';
|
| 18 |
+
import {extensionConfig} from '../config';
|
| 19 |
+
import {isPathValidOssFuzzPath} from '../ossfuzzWrappers';
|
| 20 |
+
import {systemSync} from '../utils';
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Function for setting up oss-fuzz. This clones the relevant directory
|
| 24 |
+
* and sets the oss-fuzz variable accordingly.
|
| 25 |
+
*/
|
| 26 |
+
export async function setUpOssFuzzHandler() {
|
| 27 |
+
println('Setting up oss-fuzz in /tmp/');
|
| 28 |
+
|
| 29 |
+
// First check if we already have an OSS-Fuzz path
|
| 30 |
+
const tmpOssFuzzRepositoryPath = '/tmp/oss-fuzz';
|
| 31 |
+
|
| 32 |
+
if ((await isPathValidOssFuzzPath(tmpOssFuzzRepositoryPath)) === true) {
|
| 33 |
+
println('OSS-Fuzz already exists in /tmp/oss-fuzz');
|
| 34 |
+
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const cmdToExec = 'git';
|
| 39 |
+
const args: Array<string> = [
|
| 40 |
+
'clone',
|
| 41 |
+
'https://github.com/google/oss-fuzz',
|
| 42 |
+
tmpOssFuzzRepositoryPath,
|
| 43 |
+
];
|
| 44 |
+
const [res, output] = await systemSync(cmdToExec, args);
|
| 45 |
+
if (res === false) {
|
| 46 |
+
println('Failed to clone oss-fuzz');
|
| 47 |
+
println(output);
|
| 48 |
+
return;
|
| 49 |
+
}
|
| 50 |
+
println('Finished cloning oss-fuzz');
|
| 51 |
+
|
| 52 |
+
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
|
| 53 |
+
}
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzerCFLite.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import path = require('path');
|
| 18 |
+
import * as vscode from 'vscode';
|
| 19 |
+
import {println} from '../logger';
|
| 20 |
+
import {
|
| 21 |
+
runFuzzerHandlerCFLite,
|
| 22 |
+
buildFuzzersFromWorkspaceClusterfuzzLite,
|
| 23 |
+
} from '../ossfuzzWrappers';
|
| 24 |
+
import {setStatusText} from '../utils';
|
| 25 |
+
import {commandHistory} from '../commandUtils';
|
| 26 |
+
import {extensionConfig} from '../config';
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Does an end-to-end test of a project/fuzzer. This is done by
|
| 30 |
+
* first building the project and then running the fuzzer.
|
| 31 |
+
* @param context
|
| 32 |
+
* @returns
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
export async function cmdInputCollectorTestFuzzerCFLite() {
|
| 36 |
+
setStatusText('Testing specific fuzzer: getting input');
|
| 37 |
+
// Get the fuzzer to run
|
| 38 |
+
const fuzzerNameInput = await vscode.window.showInputBox({
|
| 39 |
+
value: '',
|
| 40 |
+
placeHolder: 'Type a fuzzer name',
|
| 41 |
+
});
|
| 42 |
+
if (!fuzzerNameInput) {
|
| 43 |
+
println('Failed to get fuzzer name');
|
| 44 |
+
return;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
// Create the args object for the dispatcher
|
| 48 |
+
const args = new Object({
|
| 49 |
+
fuzzerName: fuzzerNameInput.toString(),
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
// Create a dispatcher object.
|
| 53 |
+
const commandObject = new Object({
|
| 54 |
+
commandType: 'oss-fuzz.TestFuzzerCFLite',
|
| 55 |
+
Arguments: args,
|
| 56 |
+
dispatcherFunc: cmdDispatchTestFuzzerHandlerCFLite,
|
| 57 |
+
});
|
| 58 |
+
commandHistory.push(commandObject);
|
| 59 |
+
|
| 60 |
+
await cmdDispatchTestFuzzerHandlerCFLite(args);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
async function cmdDispatchTestFuzzerHandlerCFLite(args: any) {
|
| 64 |
+
// Build the project
|
| 65 |
+
setStatusText('Test specific fuzzer: building fuzzers in workspace');
|
| 66 |
+
if (!(await buildFuzzersFromWorkspaceClusterfuzzLite())) {
|
| 67 |
+
println('Build projects');
|
| 68 |
+
return;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 72 |
+
if (!workspaceFolder) {
|
| 73 |
+
return;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
const pathOfLocal = workspaceFolder[0].uri.path;
|
| 77 |
+
println('path of local: ' + pathOfLocal);
|
| 78 |
+
|
| 79 |
+
// Run the fuzzer for 10 seconds
|
| 80 |
+
println('Running fuzzer');
|
| 81 |
+
setStatusText('Test specific fuzzer: running fuzzer ' + args.fuzzerName);
|
| 82 |
+
await runFuzzerHandlerCFLite(
|
| 83 |
+
pathOfLocal,
|
| 84 |
+
args.fuzzerName,
|
| 85 |
+
extensionConfig.numberOfSecondsForTestRuns.toString()
|
| 86 |
+
);
|
| 87 |
+
setStatusText('Test specific fuzzer: test completed of ' + args.fuzzerName);
|
| 88 |
+
return;
|
| 89 |
+
}
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/coverageHelper.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
import {Uri} from 'vscode';
|
| 19 |
+
import {println} from './logger';
|
| 20 |
+
import {
|
| 21 |
+
getOSSFuzzCloudURL,
|
| 22 |
+
getLocalOutBuildDir,
|
| 23 |
+
downloadRemoteURL,
|
| 24 |
+
} from './utils';
|
| 25 |
+
|
| 26 |
+
const path = require('path');
|
| 27 |
+
let isCodeCoverageEnabled = false;
|
| 28 |
+
|
| 29 |
+
// create a decorator type that we use to decorate small numbers
|
| 30 |
+
const codeCoveredLineDecorationType =
|
| 31 |
+
vscode.window.createTextEditorDecorationType({
|
| 32 |
+
backgroundColor: '#184916',
|
| 33 |
+
overviewRulerColor: 'blue',
|
| 34 |
+
overviewRulerLane: vscode.OverviewRulerLane.Right,
|
| 35 |
+
light: {
|
| 36 |
+
// this color will be used in light color themes
|
| 37 |
+
borderColor: 'darkblue',
|
| 38 |
+
},
|
| 39 |
+
dark: {
|
| 40 |
+
// this color will be used in dark color themes
|
| 41 |
+
borderColor: 'lightblue',
|
| 42 |
+
},
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
const missingLineDecorationType = vscode.window.createTextEditorDecorationType({
|
| 46 |
+
backgroundColor: '#6C2B34',
|
| 47 |
+
overviewRulerColor: 'blue',
|
| 48 |
+
overviewRulerLane: vscode.OverviewRulerLane.Right,
|
| 49 |
+
light: {
|
| 50 |
+
// this color will be used in light color themes
|
| 51 |
+
borderColor: 'darkblue',
|
| 52 |
+
},
|
| 53 |
+
dark: {
|
| 54 |
+
// this color will be used in dark color themes
|
| 55 |
+
borderColor: 'lightblue',
|
| 56 |
+
},
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
export async function loadSummaryJsonCoverage(
|
| 60 |
+
context: vscode.ExtensionContext,
|
| 61 |
+
codeCoverageFile: Uri
|
| 62 |
+
) {
|
| 63 |
+
const coverageSummaryRawJson = await vscode.workspace.openTextDocument(
|
| 64 |
+
codeCoverageFile
|
| 65 |
+
);
|
| 66 |
+
const jsonCodeCoverage = JSON.parse(coverageSummaryRawJson.getText());
|
| 67 |
+
return jsonCodeCoverage;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
export async function compareLocalToRemoteCoverage(
|
| 71 |
+
context: vscode.ExtensionContext,
|
| 72 |
+
projectName: string
|
| 73 |
+
) {
|
| 74 |
+
println('Checking the file matching');
|
| 75 |
+
/* Get the coverage from the remote server */
|
| 76 |
+
const urlString =
|
| 77 |
+
(await getOSSFuzzCloudURL(projectName)) + '/linux/summary.json';
|
| 78 |
+
|
| 79 |
+
println('URL: ' + urlString);
|
| 80 |
+
const codeCoverageFile: false | vscode.Uri = await downloadRemoteURL(
|
| 81 |
+
urlString,
|
| 82 |
+
'summary.json',
|
| 83 |
+
context
|
| 84 |
+
);
|
| 85 |
+
if (!codeCoverageFile) {
|
| 86 |
+
println('Could not get the coverage summary file');
|
| 87 |
+
return;
|
| 88 |
+
}
|
| 89 |
+
const remoteCoverage = await loadSummaryJsonCoverage(
|
| 90 |
+
context,
|
| 91 |
+
codeCoverageFile
|
| 92 |
+
);
|
| 93 |
+
|
| 94 |
+
/* Get the local coverage report */
|
| 95 |
+
// Compare the local coverage to the upstream coverage
|
| 96 |
+
const localSummaryCovPath =
|
| 97 |
+
(await getLocalOutBuildDir(projectName)) + '/report/linux/summary.json';
|
| 98 |
+
const localCodeCoverage = await loadSummaryJsonCoverage(
|
| 99 |
+
context,
|
| 100 |
+
vscode.Uri.file(localSummaryCovPath)
|
| 101 |
+
);
|
| 102 |
+
|
| 103 |
+
for (let i = 0; i < localCodeCoverage.data[0].files.length; i++) {
|
| 104 |
+
for (let j = 0; j < remoteCoverage.data[0].files.length; j++) {
|
| 105 |
+
// Get the file dictionary
|
| 106 |
+
const localFileData = localCodeCoverage.data[0].files[i];
|
| 107 |
+
const remoteFileData = remoteCoverage.data[0].files[j];
|
| 108 |
+
|
| 109 |
+
// If the filepaths are the same, then we match coverage data
|
| 110 |
+
if (localFileData.filename === remoteFileData.filename) {
|
| 111 |
+
const remoteFuncCount = remoteFileData.summary.functions.count;
|
| 112 |
+
const localFuncCount = localFileData.summary.functions.count;
|
| 113 |
+
|
| 114 |
+
if (localFuncCount > remoteFuncCount) {
|
| 115 |
+
println(
|
| 116 |
+
'Coverage improved in :' +
|
| 117 |
+
localFileData.filename +
|
| 118 |
+
' [' +
|
| 119 |
+
localFuncCount +
|
| 120 |
+
' : ' +
|
| 121 |
+
remoteFuncCount +
|
| 122 |
+
']'
|
| 123 |
+
);
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
*
|
| 132 |
+
* @param context Adds visualisation to the editor based on reading a code coverage file.
|
| 133 |
+
* @param codeCoverageFile
|
| 134 |
+
*/
|
| 135 |
+
export async function loadCoverageIntoWorkspace(
|
| 136 |
+
context: vscode.ExtensionContext,
|
| 137 |
+
codeCoverageFile: Uri
|
| 138 |
+
) {
|
| 139 |
+
isCodeCoverageEnabled = true;
|
| 140 |
+
|
| 141 |
+
const doc3 = await vscode.workspace.openTextDocument(codeCoverageFile);
|
| 142 |
+
const jsonCodeCoverageObj3 = JSON.parse(doc3.getText());
|
| 143 |
+
|
| 144 |
+
const codeCoverageMappingWithCoverage = new Map();
|
| 145 |
+
const codeCoverageMapMissingCoverage = new Map();
|
| 146 |
+
|
| 147 |
+
Object.entries(jsonCodeCoverageObj3['files']).forEach(entry => {
|
| 148 |
+
const [key, value] = entry;
|
| 149 |
+
println(key);
|
| 150 |
+
const filename = path.parse(key).base;
|
| 151 |
+
println('Filename base: ' + filename);
|
| 152 |
+
const objectDictionary: any = value as any;
|
| 153 |
+
const linesWithCodeCoverage: unknown[] = [];
|
| 154 |
+
println(objectDictionary['executed_lines']);
|
| 155 |
+
Object.entries(objectDictionary['executed_lines']).forEach(entryInner => {
|
| 156 |
+
const lineNumber = entryInner[1];
|
| 157 |
+
//println("executed line: " + lineNumber);
|
| 158 |
+
linesWithCodeCoverage.push(lineNumber);
|
| 159 |
+
});
|
| 160 |
+
codeCoverageMappingWithCoverage.set(filename, linesWithCodeCoverage);
|
| 161 |
+
|
| 162 |
+
const linesMissingCodeCoverage: unknown[] = [];
|
| 163 |
+
Object.entries(objectDictionary['missing_lines']).forEach(entryInner => {
|
| 164 |
+
const lineNumber = entryInner[1];
|
| 165 |
+
//println("executed line: " + line_numb);
|
| 166 |
+
linesMissingCodeCoverage.push(lineNumber);
|
| 167 |
+
});
|
| 168 |
+
codeCoverageMapMissingCoverage.set(filename, linesMissingCodeCoverage);
|
| 169 |
+
});
|
| 170 |
+
println('=========>');
|
| 171 |
+
|
| 172 |
+
println('Enabling code coverage decorator');
|
| 173 |
+
println('decorator sample is activated');
|
| 174 |
+
|
| 175 |
+
let timeout: NodeJS.Timer | undefined = undefined;
|
| 176 |
+
|
| 177 |
+
// create a decorator type that we use to decorate large numbers
|
| 178 |
+
|
| 179 |
+
let activeEditor = vscode.window.activeTextEditor;
|
| 180 |
+
|
| 181 |
+
function updateDecorations(
|
| 182 |
+
linesWithCodeCoverage: any,
|
| 183 |
+
linesWithoNoCodeCoverage: any
|
| 184 |
+
) {
|
| 185 |
+
if (!isCodeCoverageEnabled) {
|
| 186 |
+
return;
|
| 187 |
+
}
|
| 188 |
+
if (!activeEditor) {
|
| 189 |
+
return;
|
| 190 |
+
}
|
| 191 |
+
println('Filename');
|
| 192 |
+
println(activeEditor.document.fileName);
|
| 193 |
+
|
| 194 |
+
// Current file opened in the editor.
|
| 195 |
+
const nameOfCurrentFile = path.parse(activeEditor.document.fileName).base;
|
| 196 |
+
|
| 197 |
+
println('Base filename: ' + nameOfCurrentFile);
|
| 198 |
+
println('Done filename');
|
| 199 |
+
const lineNumbersWithCoverage: vscode.DecorationOptions[] = [];
|
| 200 |
+
const missingLineNumbers: vscode.DecorationOptions[] = [];
|
| 201 |
+
|
| 202 |
+
if (linesWithCodeCoverage.has(nameOfCurrentFile)) {
|
| 203 |
+
println('Has this file');
|
| 204 |
+
const elemWithCov = linesWithCodeCoverage.get(nameOfCurrentFile);
|
| 205 |
+
for (let idx = 0; idx < elemWithCov.length; idx++) {
|
| 206 |
+
const lineNo = elemWithCov[idx];
|
| 207 |
+
println('Setting up: ' + lineNo);
|
| 208 |
+
lineNumbersWithCoverage.push({
|
| 209 |
+
range: new vscode.Range(lineNo - 1, 0, lineNo, 0),
|
| 210 |
+
});
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
const elemNoCov = linesWithoNoCodeCoverage.get(nameOfCurrentFile);
|
| 214 |
+
for (let idx = 0; idx < elemNoCov.length; idx++) {
|
| 215 |
+
const lineNo = elemNoCov[idx];
|
| 216 |
+
println('Setting up: ' + lineNo);
|
| 217 |
+
missingLineNumbers.push({
|
| 218 |
+
range: new vscode.Range(lineNo - 1, 0, lineNo, 0),
|
| 219 |
+
});
|
| 220 |
+
}
|
| 221 |
+
} else {
|
| 222 |
+
println('Does not have this file');
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
activeEditor.setDecorations(
|
| 226 |
+
codeCoveredLineDecorationType,
|
| 227 |
+
lineNumbersWithCoverage
|
| 228 |
+
);
|
| 229 |
+
activeEditor.setDecorations(missingLineDecorationType, missingLineNumbers);
|
| 230 |
+
//activeEditor.setDecorations(largeNumberDecorationType, largeNumbers);
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
function triggerUpdateDecorations(
|
| 234 |
+
throttle = false,
|
| 235 |
+
covMap: any,
|
| 236 |
+
covMisMap: any
|
| 237 |
+
) {
|
| 238 |
+
if (timeout) {
|
| 239 |
+
clearTimeout(timeout);
|
| 240 |
+
timeout = undefined;
|
| 241 |
+
}
|
| 242 |
+
if (throttle) {
|
| 243 |
+
//timeout = setTimeout(updateDecorations, 500);
|
| 244 |
+
updateDecorations(covMap, covMisMap);
|
| 245 |
+
} else {
|
| 246 |
+
updateDecorations(covMap, covMisMap);
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
if (activeEditor) {
|
| 251 |
+
triggerUpdateDecorations(
|
| 252 |
+
false,
|
| 253 |
+
codeCoverageMappingWithCoverage,
|
| 254 |
+
codeCoverageMapMissingCoverage
|
| 255 |
+
);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
vscode.window.onDidChangeActiveTextEditor(
|
| 259 |
+
editor => {
|
| 260 |
+
activeEditor = editor;
|
| 261 |
+
if (editor) {
|
| 262 |
+
triggerUpdateDecorations(
|
| 263 |
+
false,
|
| 264 |
+
codeCoverageMappingWithCoverage,
|
| 265 |
+
codeCoverageMapMissingCoverage
|
| 266 |
+
);
|
| 267 |
+
}
|
| 268 |
+
},
|
| 269 |
+
null,
|
| 270 |
+
context.subscriptions
|
| 271 |
+
);
|
| 272 |
+
|
| 273 |
+
vscode.workspace.onDidChangeTextDocument(
|
| 274 |
+
event => {
|
| 275 |
+
if (activeEditor && event.document === activeEditor.document) {
|
| 276 |
+
triggerUpdateDecorations(
|
| 277 |
+
true,
|
| 278 |
+
codeCoverageMappingWithCoverage,
|
| 279 |
+
codeCoverageMapMissingCoverage
|
| 280 |
+
);
|
| 281 |
+
}
|
| 282 |
+
},
|
| 283 |
+
null,
|
| 284 |
+
context.subscriptions
|
| 285 |
+
);
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
/**
|
| 289 |
+
* Removes the values from the mappings used to track code coverage. As a
|
| 290 |
+
* result, the visualisation disappears.
|
| 291 |
+
*/
|
| 292 |
+
export async function clearCoverage() {
|
| 293 |
+
// Set global indicator.
|
| 294 |
+
const activeEditor = vscode.window.activeTextEditor;
|
| 295 |
+
isCodeCoverageEnabled = false;
|
| 296 |
+
if (activeEditor) {
|
| 297 |
+
activeEditor.setDecorations(codeCoveredLineDecorationType, []);
|
| 298 |
+
activeEditor.setDecorations(missingLineDecorationType, []);
|
| 299 |
+
}
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
|
| 19 |
+
import {clearCoverage} from './coverageHelper';
|
| 20 |
+
import {println} from './logger';
|
| 21 |
+
|
| 22 |
+
// Import the command dispatcher functions
|
| 23 |
+
import {cmdInputCollectorRunSpecificFuzzer} from './commands/cmdRunFuzzer';
|
| 24 |
+
import {cmdInputCollectorBuildFuzzersFromWorkspace} from './commands/cmdBuildFuzzerFromWorkspace';
|
| 25 |
+
import {cmdInputCollectorBuildFuzzersFromWorkspaceCFLite} from './commands/cmdBuildFuzzerFromWorkspaceCFLite';
|
| 26 |
+
import {cmdInputCollectorTestFuzzerCFLite} from './commands/cmdTestFuzzerCFLite';
|
| 27 |
+
import {cmdDispatcherRe} from './commands/cmdRedo';
|
| 28 |
+
import {setupCIFuzzHandler} from './commands/cmdSetupCIFuzz';
|
| 29 |
+
import {cmdInputCollectorTestFuzzer} from './commands/cmdTestFuzzer';
|
| 30 |
+
import {displayCodeCoverageFromOssFuzz} from './commands/cmdDisplayCoverage';
|
| 31 |
+
import {createOssFuzzSetup} from './commands/cmdCreateOSSFuzzSetup';
|
| 32 |
+
import {runEndToEndAndGetCoverage} from './commands/cmdEndToEndCoverage';
|
| 33 |
+
import {listFuzzersHandler} from './commands/cmdListFuzzers';
|
| 34 |
+
import {cmdInputCollectorReproduceTestcase} from './commands/cmdReproduceTestcase';
|
| 35 |
+
import {cmdDispatcherTemplate} from './commands/cmdTemplate';
|
| 36 |
+
import {runGetOptimalTargetsHandler} from './commands/cmdFIGetOptimalTargets';
|
| 37 |
+
import {setUpFuzzIntrospectorHandler} from './commands/cmdSetupFI';
|
| 38 |
+
import {runFuzzIntrospectorHandler} from './commands/cmdRunFI';
|
| 39 |
+
import {cmdDispatcherGenerateClusterfuzzLite} from './commands/cmdDispatcherGenerateClusterfuzzLite';
|
| 40 |
+
import {setUpOssFuzzHandler} from './commands/cmdSetupOSSFuzz';
|
| 41 |
+
import {setOssFuzzPath} from './commands/cmdSetOSSFuzzPath';
|
| 42 |
+
import {extensionConfig} from './config';
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Extension entrypoint. Activate the extension and register the commands.
|
| 46 |
+
*/
|
| 47 |
+
export function activate(context: vscode.ExtensionContext) {
|
| 48 |
+
console.log('Activating extension)');
|
| 49 |
+
extensionConfig.printConfig();
|
| 50 |
+
println('OSS-Fuzz extension is now active!');
|
| 51 |
+
|
| 52 |
+
// Command registration
|
| 53 |
+
context.subscriptions.push(
|
| 54 |
+
vscode.commands.registerCommand('oss-fuzz.SetUp', async () => {
|
| 55 |
+
println('CMD start: SetUp');
|
| 56 |
+
await setUpOssFuzzHandler();
|
| 57 |
+
println('CMD end: SetUp');
|
| 58 |
+
})
|
| 59 |
+
);
|
| 60 |
+
|
| 61 |
+
context.subscriptions.push(
|
| 62 |
+
vscode.commands.registerCommand('oss-fuzz.RunFuzzer', async () => {
|
| 63 |
+
println('CMD start: Run Fuzzer');
|
| 64 |
+
//await runFuzzerHandler('', '', '', '');
|
| 65 |
+
cmdInputCollectorRunSpecificFuzzer();
|
| 66 |
+
println('CMD end: Run Fuzzer');
|
| 67 |
+
})
|
| 68 |
+
);
|
| 69 |
+
|
| 70 |
+
context.subscriptions.push(
|
| 71 |
+
vscode.commands.registerCommand('oss-fuzz.ListFuzzers', async () => {
|
| 72 |
+
println('CMD start: ListFuzzers');
|
| 73 |
+
await listFuzzersHandler();
|
| 74 |
+
println('CMD end: ListFuzzers');
|
| 75 |
+
})
|
| 76 |
+
);
|
| 77 |
+
|
| 78 |
+
context.subscriptions.push(
|
| 79 |
+
vscode.commands.registerCommand('oss-fuzz.SetOSSFuzzPath', async () => {
|
| 80 |
+
println('CMD start: SetOSSFuzzPath');
|
| 81 |
+
await setOssFuzzPath();
|
| 82 |
+
println('CMD end: SetOSSFuzzPath');
|
| 83 |
+
})
|
| 84 |
+
);
|
| 85 |
+
|
| 86 |
+
context.subscriptions.push(
|
| 87 |
+
vscode.commands.registerCommand('oss-fuzz.GetCodeCoverage', async () => {
|
| 88 |
+
println('CMD start: GetCodeCoverage');
|
| 89 |
+
await displayCodeCoverageFromOssFuzz(context);
|
| 90 |
+
println('CMD end: GetCodeCoverage');
|
| 91 |
+
})
|
| 92 |
+
);
|
| 93 |
+
|
| 94 |
+
context.subscriptions.push(
|
| 95 |
+
vscode.commands.registerCommand('oss-fuzz.ClearCodeCoverage', async () => {
|
| 96 |
+
println('CMD start: ClearCodeCoverage');
|
| 97 |
+
await clearCoverage();
|
| 98 |
+
println('CMD end: ClearCodeCoverage');
|
| 99 |
+
})
|
| 100 |
+
);
|
| 101 |
+
|
| 102 |
+
context.subscriptions.push(
|
| 103 |
+
vscode.commands.registerCommand('oss-fuzz.CreateOSSFuzzSetup', async () => {
|
| 104 |
+
println('CMD start: CreateOSSFuzzSetup');
|
| 105 |
+
await createOssFuzzSetup();
|
| 106 |
+
println('CMD end: CreateOSSFuzzSetup');
|
| 107 |
+
})
|
| 108 |
+
);
|
| 109 |
+
|
| 110 |
+
context.subscriptions.push(
|
| 111 |
+
vscode.commands.registerCommand('oss-fuzz.WSBuildFuzzers', async () => {
|
| 112 |
+
println('CMD start: WSBuildFuzzers3');
|
| 113 |
+
await cmdInputCollectorBuildFuzzersFromWorkspace();
|
| 114 |
+
println('CMD end: WSBuildFuzzers4');
|
| 115 |
+
})
|
| 116 |
+
);
|
| 117 |
+
|
| 118 |
+
context.subscriptions.push(
|
| 119 |
+
vscode.commands.registerCommand('oss-fuzz.SetupCIFuzz', async () => {
|
| 120 |
+
println('CMD start: SetupCIFuzz');
|
| 121 |
+
await setupCIFuzzHandler();
|
| 122 |
+
println('CMD end: SetupCIFuzz');
|
| 123 |
+
})
|
| 124 |
+
);
|
| 125 |
+
|
| 126 |
+
context.subscriptions.push(
|
| 127 |
+
vscode.commands.registerCommand('oss-fuzz.testFuzzer', async () => {
|
| 128 |
+
println('CMD start: testFuzzer');
|
| 129 |
+
await cmdInputCollectorTestFuzzer();
|
| 130 |
+
println('CMD end: testFuzzer');
|
| 131 |
+
})
|
| 132 |
+
);
|
| 133 |
+
|
| 134 |
+
context.subscriptions.push(
|
| 135 |
+
vscode.commands.registerCommand('oss-fuzz.testCodeCoverage', async () => {
|
| 136 |
+
println('CMD start: testCodeCoverage');
|
| 137 |
+
await runEndToEndAndGetCoverage(context);
|
| 138 |
+
println('CMD end: testCodeCoverage');
|
| 139 |
+
})
|
| 140 |
+
);
|
| 141 |
+
|
| 142 |
+
context.subscriptions.push(
|
| 143 |
+
vscode.commands.registerCommand('oss-fuzz.Reproduce', async () => {
|
| 144 |
+
println('CMD start: Reproduce');
|
| 145 |
+
await cmdInputCollectorReproduceTestcase();
|
| 146 |
+
println('CMD end: Reproduce');
|
| 147 |
+
})
|
| 148 |
+
);
|
| 149 |
+
|
| 150 |
+
context.subscriptions.push(
|
| 151 |
+
vscode.commands.registerCommand('oss-fuzz.Redo', async () => {
|
| 152 |
+
println('CMD start: Re');
|
| 153 |
+
await cmdDispatcherRe();
|
| 154 |
+
println('CMD end: Re');
|
| 155 |
+
})
|
| 156 |
+
);
|
| 157 |
+
|
| 158 |
+
context.subscriptions.push(
|
| 159 |
+
vscode.commands.registerCommand('oss-fuzz.Template', async () => {
|
| 160 |
+
println('CMD start: remplate');
|
| 161 |
+
await cmdDispatcherTemplate(context);
|
| 162 |
+
println('CMD end: template');
|
| 163 |
+
})
|
| 164 |
+
);
|
| 165 |
+
|
| 166 |
+
context.subscriptions.push(
|
| 167 |
+
vscode.commands.registerCommand(
|
| 168 |
+
'oss-fuzz.GenerateClusterfuzzLite',
|
| 169 |
+
async () => {
|
| 170 |
+
println('CMD start: GenerateClusterfuzzLite');
|
| 171 |
+
await cmdDispatcherGenerateClusterfuzzLite(context);
|
| 172 |
+
println('CMD end: GenerateClusterfuzzLite');
|
| 173 |
+
}
|
| 174 |
+
)
|
| 175 |
+
);
|
| 176 |
+
|
| 177 |
+
context.subscriptions.push(
|
| 178 |
+
vscode.commands.registerCommand(
|
| 179 |
+
'oss-fuzz.WSBuildFuzzersCFLite',
|
| 180 |
+
async () => {
|
| 181 |
+
println('CMD start: WSBuildFuzzersCFLite');
|
| 182 |
+
await cmdInputCollectorBuildFuzzersFromWorkspaceCFLite();
|
| 183 |
+
println('CMD end: WSBuildFuzzersCFLite');
|
| 184 |
+
}
|
| 185 |
+
)
|
| 186 |
+
);
|
| 187 |
+
|
| 188 |
+
context.subscriptions.push(
|
| 189 |
+
vscode.commands.registerCommand('oss-fuzz.testFuzzerCFLite', async () => {
|
| 190 |
+
println('CMD start: testFuzzerCFLite');
|
| 191 |
+
await cmdInputCollectorTestFuzzerCFLite();
|
| 192 |
+
println('CMD end: testFuzzerCFLite');
|
| 193 |
+
})
|
| 194 |
+
);
|
| 195 |
+
|
| 196 |
+
context.subscriptions.push(
|
| 197 |
+
vscode.commands.registerCommand(
|
| 198 |
+
'oss-fuzz.setupFuzzIntrospector',
|
| 199 |
+
async () => {
|
| 200 |
+
println('CMD start: setup FI');
|
| 201 |
+
await setUpFuzzIntrospectorHandler();
|
| 202 |
+
}
|
| 203 |
+
)
|
| 204 |
+
);
|
| 205 |
+
|
| 206 |
+
context.subscriptions.push(
|
| 207 |
+
vscode.commands.registerCommand(
|
| 208 |
+
'oss-fuzz.runFuzzIntrospector',
|
| 209 |
+
async () => {
|
| 210 |
+
println('CMD start: run Fuzz Introspector');
|
| 211 |
+
await runFuzzIntrospectorHandler();
|
| 212 |
+
}
|
| 213 |
+
)
|
| 214 |
+
);
|
| 215 |
+
|
| 216 |
+
context.subscriptions.push(
|
| 217 |
+
vscode.commands.registerCommand('oss-fuzz.GetOptimalTargets', async () => {
|
| 218 |
+
println('CMD start: run GetOptimalTargets');
|
| 219 |
+
await runGetOptimalTargetsHandler();
|
| 220 |
+
})
|
| 221 |
+
);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
// This method is called when your extension is deactivated
|
| 225 |
+
export function deactivate() {
|
| 226 |
+
println('Deactivating the extension');
|
| 227 |
+
}
|
local-test-commons-compress-delta-03/fuzz-tooling/tools/vscode-extension/src/fuzzIntrospectorHelper.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2025 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
|
| 19 |
+
import {println} from './logger';
|
| 20 |
+
import {extensionConfig} from './config';
|
| 21 |
+
import {isPathValidOssFuzzPath} from './ossfuzzWrappers';
|
| 22 |
+
import {systemSync} from './utils';
|
| 23 |
+
|
| 24 |
+
const fs = require('fs');
|
| 25 |
+
|
| 26 |
+
export async function setUpFuzzIntrospector() {
|
| 27 |
+
println('Setting up oss-fuzz in /tmp/');
|
| 28 |
+
|
| 29 |
+
// First check if we already have Fuzz Introspector installed.
|
| 30 |
+
const tmpOssFuzzRepositoryPath = '/tmp/fi-tmp-env';
|
| 31 |
+
|
| 32 |
+
if ((await isPathValidOssFuzzPath(tmpOssFuzzRepositoryPath)) === true) {
|
| 33 |
+
println('Fuzz Introspector virtual env already exists in /tmp/fi-tmp-env');
|
| 34 |
+
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const cmdToExec = 'python3.11';
|
| 39 |
+
const args: Array<string> = ['-m', 'virtualenv', tmpOssFuzzRepositoryPath];
|
| 40 |
+
const [res, output] = await systemSync(cmdToExec, args);
|
| 41 |
+
if (res === false) {
|
| 42 |
+
println('Failed to create virtual environment');
|
| 43 |
+
println(output);
|
| 44 |
+
return;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
const cmdToExec2 = '/tmp/fi-tmp-env/bin/python3.11';
|
| 48 |
+
const args2: Array<string> = [
|
| 49 |
+
'-m',
|
| 50 |
+
'pip',
|
| 51 |
+
'install',
|
| 52 |
+
'fuzz-introspector==0.1.6',
|
| 53 |
+
];
|
| 54 |
+
const [res2, output2] = await systemSync(cmdToExec2, args2);
|
| 55 |
+
if (res2 === false) {
|
| 56 |
+
println('Failed to create virtual environment');
|
| 57 |
+
println(output2);
|
| 58 |
+
return;
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
export async function runFuzzIntrospector() {
|
| 63 |
+
println('Setting up oss-fuzz in /tmp/');
|
| 64 |
+
|
| 65 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 66 |
+
if (!workspaceFolder) {
|
| 67 |
+
return;
|
| 68 |
+
}
|
| 69 |
+
const pathOfLocal = workspaceFolder[0].uri.fsPath;
|
| 70 |
+
println('path of local: ' + pathOfLocal);
|
| 71 |
+
|
| 72 |
+
// First check if we already have Fuzz Introspector installed.
|
| 73 |
+
const tmpOssFuzzRepositoryPath = '/tmp/fi-tmp-env';
|
| 74 |
+
|
| 75 |
+
if ((await isPathValidOssFuzzPath(tmpOssFuzzRepositoryPath)) === true) {
|
| 76 |
+
println('Fuzz Introspector virtual env already exists in /tmp/fi-tmp-env');
|
| 77 |
+
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
|
| 78 |
+
return;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
await systemSync('mkdir', ['-p', '/tmp/out-fi/']);
|
| 82 |
+
|
| 83 |
+
const cmdToExec = '/tmp/fi-tmp-env/bin/fuzz-introspector';
|
| 84 |
+
const args: Array<string> = [
|
| 85 |
+
'full',
|
| 86 |
+
'--target_dir=' + pathOfLocal,
|
| 87 |
+
'--out-dir=/tmp/out-fi',
|
| 88 |
+
];
|
| 89 |
+
const [res, output] = await systemSync(cmdToExec, args);
|
| 90 |
+
if (res === false) {
|
| 91 |
+
println('Failed run FI');
|
| 92 |
+
println(output);
|
| 93 |
+
return;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
export async function getOptimalTargetsFromIntrospector() {
|
| 98 |
+
if (!fs.existsSync('/tmp/out-fi/summary.json')) {
|
| 99 |
+
println('There are no introspector reports. Please run introspector first');
|
| 100 |
+
}
|
| 101 |
+
const json_data = fs.readFileSync('/tmp/out-fi/summary.json');
|
| 102 |
+
// println(json_data);
|
| 103 |
+
|
| 104 |
+
const jsonCodeCoverage = JSON.parse(json_data);
|
| 105 |
+
|
| 106 |
+
println('Optimal targets');
|
| 107 |
+
Object.entries(jsonCodeCoverage['analyses']['OptimalTargets']).forEach(
|
| 108 |
+
entry => {
|
| 109 |
+
const [key, value] = entry;
|
| 110 |
+
const objectDictionary: any = value as any;
|
| 111 |
+
println(JSON.stringify(objectDictionary, null, 2));
|
| 112 |
+
}
|
| 113 |
+
);
|
| 114 |
+
println('--------------------------');
|
| 115 |
+
|
| 116 |
+
return;
|
| 117 |
+
}
|