The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

772 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. inline uint16 readUnalignedLittleEndianShort (const void* buffer)
  20. {
  21. auto data = readUnaligned<uint16> (buffer);
  22. return ByteOrder::littleEndianShort (&data);
  23. }
  24. inline uint32 readUnalignedLittleEndianInt (const void* buffer)
  25. {
  26. auto data = readUnaligned<uint32> (buffer);
  27. return ByteOrder::littleEndianInt (&data);
  28. }
  29. struct ZipFile::ZipEntryHolder
  30. {
  31. ZipEntryHolder (const char* buffer, int fileNameLen)
  32. {
  33. isCompressed = readUnalignedLittleEndianShort (buffer + 10) != 0;
  34. entry.fileTime = parseFileTime (readUnalignedLittleEndianShort (buffer + 12),
  35. readUnalignedLittleEndianShort (buffer + 14));
  36. compressedSize = (int64) readUnalignedLittleEndianInt (buffer + 20);
  37. entry.uncompressedSize = (int64) readUnalignedLittleEndianInt (buffer + 24);
  38. streamOffset = (int64) readUnalignedLittleEndianInt (buffer + 42);
  39. entry.externalFileAttributes = readUnalignedLittleEndianInt (buffer + 38);
  40. auto fileType = (entry.externalFileAttributes >> 28) & 0xf;
  41. entry.isSymbolicLink = (fileType == 0xA);
  42. entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  43. }
  44. static Time parseFileTime (uint32 time, uint32 date) noexcept
  45. {
  46. auto year = (int) (1980 + (date >> 9));
  47. auto month = (int) (((date >> 5) & 15) - 1);
  48. auto day = (int) (date & 31);
  49. auto hours = (int) time >> 11;
  50. auto minutes = (int) ((time >> 5) & 63);
  51. auto seconds = (int) ((time & 31) << 1);
  52. return { year, month, day, hours, minutes, seconds };
  53. }
  54. ZipEntry entry;
  55. int64 streamOffset, compressedSize;
  56. bool isCompressed;
  57. };
  58. //==============================================================================
  59. static int64 findCentralDirectoryFileHeader (InputStream& input, int& numEntries)
  60. {
  61. BufferedInputStream in (input, 8192);
  62. in.setPosition (in.getTotalLength());
  63. auto pos = in.getPosition();
  64. auto lowestPos = jmax ((int64) 0, pos - 1048576);
  65. char buffer[32] = {};
  66. while (pos > lowestPos)
  67. {
  68. in.setPosition (pos - 22);
  69. pos = in.getPosition();
  70. memcpy (buffer + 22, buffer, 4);
  71. if (in.read (buffer, 22) != 22)
  72. return 0;
  73. for (int i = 0; i < 22; ++i)
  74. {
  75. if (readUnalignedLittleEndianInt (buffer + i) == 0x06054b50)
  76. {
  77. in.setPosition (pos + i);
  78. in.read (buffer, 22);
  79. numEntries = readUnalignedLittleEndianShort (buffer + 10);
  80. auto offset = (int64) readUnalignedLittleEndianInt (buffer + 16);
  81. if (offset >= 4)
  82. {
  83. in.setPosition (offset);
  84. // This is a workaround for some zip files which seem to contain the
  85. // wrong offset for the central directory - instead of including the
  86. // header, they point to the byte immediately after it.
  87. if (in.readInt() != 0x02014b50)
  88. {
  89. in.setPosition (offset - 4);
  90. if (in.readInt() == 0x02014b50)
  91. offset -= 4;
  92. }
  93. }
  94. return offset;
  95. }
  96. }
  97. }
  98. return 0;
  99. }
  100. static bool hasSymbolicPart (const File& root, const File& f)
  101. {
  102. jassert (root == f || f.isAChildOf (root));
  103. for (auto p = f; p != root; p = p.getParentDirectory())
  104. {
  105. if (p.isSymbolicLink())
  106. return true;
  107. }
  108. return false;
  109. }
  110. //==============================================================================
  111. struct ZipFile::ZipInputStream final : public InputStream
  112. {
  113. ZipInputStream (ZipFile& zf, const ZipFile::ZipEntryHolder& zei)
  114. : file (zf),
  115. zipEntryHolder (zei),
  116. inputStream (zf.inputStream)
  117. {
  118. if (zf.inputSource != nullptr)
  119. {
  120. streamToDelete.reset (file.inputSource->createInputStream());
  121. inputStream = streamToDelete.get();
  122. }
  123. else
  124. {
  125. #if JUCE_DEBUG
  126. zf.streamCounter.numOpenStreams++;
  127. #endif
  128. }
  129. char buffer[30];
  130. if (inputStream != nullptr
  131. && inputStream->setPosition (zei.streamOffset)
  132. && inputStream->read (buffer, 30) == 30
  133. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  134. {
  135. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  136. + ByteOrder::littleEndianShort (buffer + 28);
  137. }
  138. }
  139. ~ZipInputStream() override
  140. {
  141. #if JUCE_DEBUG
  142. if (inputStream != nullptr && inputStream == file.inputStream)
  143. file.streamCounter.numOpenStreams--;
  144. #endif
  145. }
  146. int64 getTotalLength() override
  147. {
  148. return zipEntryHolder.compressedSize;
  149. }
  150. int read (void* buffer, int howMany) override
  151. {
  152. if (headerSize <= 0)
  153. return 0;
  154. howMany = (int) jmin ((int64) howMany, zipEntryHolder.compressedSize - pos);
  155. if (inputStream == nullptr)
  156. return 0;
  157. int num;
  158. if (inputStream == file.inputStream)
  159. {
  160. const ScopedLock sl (file.lock);
  161. inputStream->setPosition (pos + zipEntryHolder.streamOffset + headerSize);
  162. num = inputStream->read (buffer, howMany);
  163. }
  164. else
  165. {
  166. inputStream->setPosition (pos + zipEntryHolder.streamOffset + headerSize);
  167. num = inputStream->read (buffer, howMany);
  168. }
  169. pos += num;
  170. return num;
  171. }
  172. bool isExhausted() override
  173. {
  174. return headerSize <= 0 || pos >= zipEntryHolder.compressedSize;
  175. }
  176. int64 getPosition() override
  177. {
  178. return pos;
  179. }
  180. bool setPosition (int64 newPos) override
  181. {
  182. pos = jlimit ((int64) 0, zipEntryHolder.compressedSize, newPos);
  183. return true;
  184. }
  185. private:
  186. ZipFile& file;
  187. ZipEntryHolder zipEntryHolder;
  188. int64 pos = 0;
  189. int headerSize = 0;
  190. InputStream* inputStream;
  191. std::unique_ptr<InputStream> streamToDelete;
  192. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ZipInputStream)
  193. };
  194. //==============================================================================
  195. ZipFile::ZipFile (InputStream* stream, bool deleteStreamWhenDestroyed)
  196. : inputStream (stream)
  197. {
  198. if (deleteStreamWhenDestroyed)
  199. streamToDelete.reset (inputStream);
  200. init();
  201. }
  202. ZipFile::ZipFile (InputStream& stream) : inputStream (&stream)
  203. {
  204. init();
  205. }
  206. ZipFile::ZipFile (const File& file) : inputSource (new FileInputSource (file))
  207. {
  208. init();
  209. }
  210. ZipFile::ZipFile (InputSource* source) : inputSource (source)
  211. {
  212. init();
  213. }
  214. ZipFile::~ZipFile()
  215. {
  216. entries.clear();
  217. }
  218. #if JUCE_DEBUG
  219. ZipFile::OpenStreamCounter::~OpenStreamCounter()
  220. {
  221. /* If you hit this assertion, it means you've created a stream to read one of the items in the
  222. zipfile, but you've forgotten to delete that stream object before deleting the file..
  223. Streams can't be kept open after the file is deleted because they need to share the input
  224. stream that is managed by the ZipFile object.
  225. */
  226. jassert (numOpenStreams == 0);
  227. }
  228. #endif
  229. //==============================================================================
  230. int ZipFile::getNumEntries() const noexcept
  231. {
  232. return entries.size();
  233. }
  234. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const noexcept
  235. {
  236. if (auto* zei = entries[index])
  237. return &(zei->entry);
  238. return nullptr;
  239. }
  240. int ZipFile::getIndexOfFileName (const String& fileName, bool ignoreCase) const noexcept
  241. {
  242. for (int i = 0; i < entries.size(); ++i)
  243. {
  244. auto& entryFilename = entries.getUnchecked (i)->entry.filename;
  245. if (ignoreCase ? entryFilename.equalsIgnoreCase (fileName)
  246. : entryFilename == fileName)
  247. return i;
  248. }
  249. return -1;
  250. }
  251. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName, bool ignoreCase) const noexcept
  252. {
  253. return getEntry (getIndexOfFileName (fileName, ignoreCase));
  254. }
  255. InputStream* ZipFile::createStreamForEntry (const int index)
  256. {
  257. InputStream* stream = nullptr;
  258. if (auto* zei = entries[index])
  259. {
  260. stream = new ZipInputStream (*this, *zei);
  261. if (zei->isCompressed)
  262. {
  263. stream = new GZIPDecompressorInputStream (stream, true,
  264. GZIPDecompressorInputStream::deflateFormat,
  265. zei->entry.uncompressedSize);
  266. // (much faster to unzip in big blocks using a buffer..)
  267. stream = new BufferedInputStream (stream, 32768, true);
  268. }
  269. }
  270. return stream;
  271. }
  272. InputStream* ZipFile::createStreamForEntry (const ZipEntry& entry)
  273. {
  274. for (int i = 0; i < entries.size(); ++i)
  275. if (&entries.getUnchecked (i)->entry == &entry)
  276. return createStreamForEntry (i);
  277. return nullptr;
  278. }
  279. void ZipFile::sortEntriesByFilename()
  280. {
  281. std::sort (entries.begin(), entries.end(),
  282. [] (const ZipEntryHolder* e1, const ZipEntryHolder* e2) { return e1->entry.filename < e2->entry.filename; });
  283. }
  284. //==============================================================================
  285. void ZipFile::init()
  286. {
  287. std::unique_ptr<InputStream> toDelete;
  288. InputStream* in = inputStream;
  289. if (inputSource != nullptr)
  290. {
  291. in = inputSource->createInputStream();
  292. toDelete.reset (in);
  293. }
  294. if (in != nullptr)
  295. {
  296. int numEntries = 0;
  297. auto centralDirectoryPos = findCentralDirectoryFileHeader (*in, numEntries);
  298. if (centralDirectoryPos >= 0 && centralDirectoryPos < in->getTotalLength())
  299. {
  300. auto size = (size_t) (in->getTotalLength() - centralDirectoryPos);
  301. in->setPosition (centralDirectoryPos);
  302. MemoryBlock headerData;
  303. if (in->readIntoMemoryBlock (headerData, (ssize_t) size) == size)
  304. {
  305. size_t pos = 0;
  306. for (int i = 0; i < numEntries; ++i)
  307. {
  308. if (pos + 46 > size)
  309. break;
  310. auto* buffer = static_cast<const char*> (headerData.getData()) + pos;
  311. auto fileNameLen = readUnalignedLittleEndianShort (buffer + 28u);
  312. if (pos + 46 + fileNameLen > size)
  313. break;
  314. entries.add (new ZipEntryHolder (buffer, fileNameLen));
  315. pos += 46u + fileNameLen
  316. + readUnalignedLittleEndianShort (buffer + 30u)
  317. + readUnalignedLittleEndianShort (buffer + 32u);
  318. }
  319. }
  320. }
  321. }
  322. }
  323. Result ZipFile::uncompressTo (const File& targetDirectory,
  324. const bool shouldOverwriteFiles)
  325. {
  326. for (int i = 0; i < entries.size(); ++i)
  327. {
  328. auto result = uncompressEntry (i, targetDirectory, shouldOverwriteFiles);
  329. if (result.failed())
  330. return result;
  331. }
  332. return Result::ok();
  333. }
  334. Result ZipFile::uncompressEntry (int index, const File& targetDirectory, bool shouldOverwriteFiles)
  335. {
  336. return uncompressEntry (index,
  337. targetDirectory,
  338. shouldOverwriteFiles ? OverwriteFiles::yes : OverwriteFiles::no,
  339. FollowSymlinks::no);
  340. }
  341. Result ZipFile::uncompressEntry (int index, const File& targetDirectory, OverwriteFiles overwriteFiles, FollowSymlinks followSymlinks)
  342. {
  343. auto* zei = entries.getUnchecked (index);
  344. #if JUCE_WINDOWS
  345. auto entryPath = zei->entry.filename;
  346. #else
  347. auto entryPath = zei->entry.filename.replaceCharacter ('\\', '/');
  348. #endif
  349. if (entryPath.isEmpty())
  350. return Result::ok();
  351. auto targetFile = targetDirectory.getChildFile (entryPath);
  352. if (! targetFile.isAChildOf (targetDirectory))
  353. return Result::fail ("Entry " + entryPath + " is outside the target directory");
  354. if (entryPath.endsWithChar ('/') || entryPath.endsWithChar ('\\'))
  355. return targetFile.createDirectory(); // (entry is a directory, not a file)
  356. std::unique_ptr<InputStream> in (createStreamForEntry (index));
  357. if (in == nullptr)
  358. return Result::fail ("Failed to open the zip file for reading");
  359. if (targetFile.exists())
  360. {
  361. if (overwriteFiles == OverwriteFiles::no)
  362. return Result::ok();
  363. if (! targetFile.deleteFile())
  364. return Result::fail ("Failed to write to target file: " + targetFile.getFullPathName());
  365. }
  366. if (followSymlinks == FollowSymlinks::no && hasSymbolicPart (targetDirectory, targetFile.getParentDirectory()))
  367. return Result::fail ("Parent directory leads through symlink for target file: " + targetFile.getFullPathName());
  368. if (! targetFile.getParentDirectory().createDirectory())
  369. return Result::fail ("Failed to create target folder: " + targetFile.getParentDirectory().getFullPathName());
  370. if (zei->entry.isSymbolicLink)
  371. {
  372. String originalFilePath (in->readEntireStreamAsString()
  373. .replaceCharacter (L'/', File::getSeparatorChar()));
  374. if (! File::createSymbolicLink (targetFile, originalFilePath, true))
  375. return Result::fail ("Failed to create symbolic link: " + originalFilePath);
  376. }
  377. else
  378. {
  379. FileOutputStream out (targetFile);
  380. if (out.failedToOpen())
  381. return Result::fail ("Failed to write to target file: " + targetFile.getFullPathName());
  382. out << *in;
  383. }
  384. targetFile.setCreationTime (zei->entry.fileTime);
  385. targetFile.setLastModificationTime (zei->entry.fileTime);
  386. targetFile.setLastAccessTime (zei->entry.fileTime);
  387. return Result::ok();
  388. }
  389. //==============================================================================
  390. struct ZipFile::Builder::Item
  391. {
  392. Item (const File& f, InputStream* s, int compression, const String& storedPath, Time time)
  393. : file (f), stream (s), storedPathname (storedPath), fileTime (time), compressionLevel (compression)
  394. {
  395. symbolicLink = (file.exists() && file.isSymbolicLink());
  396. }
  397. bool writeData (OutputStream& target, const int64 overallStartPosition)
  398. {
  399. MemoryOutputStream compressedData ((size_t) file.getSize());
  400. if (symbolicLink)
  401. {
  402. auto relativePath = file.getNativeLinkedTarget().replaceCharacter (File::getSeparatorChar(), L'/');
  403. uncompressedSize = relativePath.length();
  404. checksum = zlibNamespace::crc32 (0, (uint8_t*) relativePath.toRawUTF8(), (unsigned int) uncompressedSize);
  405. compressedData << relativePath;
  406. }
  407. else if (compressionLevel > 0)
  408. {
  409. GZIPCompressorOutputStream compressor (compressedData, compressionLevel,
  410. GZIPCompressorOutputStream::windowBitsRaw);
  411. if (! writeSource (compressor))
  412. return false;
  413. }
  414. else
  415. {
  416. if (! writeSource (compressedData))
  417. return false;
  418. }
  419. compressedSize = (int64) compressedData.getDataSize();
  420. headerStart = target.getPosition() - overallStartPosition;
  421. target.writeInt (0x04034b50);
  422. writeFlagsAndSizes (target);
  423. target << storedPathname
  424. << compressedData;
  425. return true;
  426. }
  427. bool writeDirectoryEntry (OutputStream& target)
  428. {
  429. target.writeInt (0x02014b50);
  430. target.writeShort (symbolicLink ? 0x0314 : 0x0014);
  431. writeFlagsAndSizes (target);
  432. target.writeShort (0); // comment length
  433. target.writeShort (0); // start disk num
  434. target.writeShort (0); // internal attributes
  435. target.writeInt ((int) (symbolicLink ? 0xA1ED0000 : 0)); // external attributes
  436. target.writeInt ((int) (uint32) headerStart);
  437. target << storedPathname;
  438. return true;
  439. }
  440. private:
  441. const File file;
  442. std::unique_ptr<InputStream> stream;
  443. String storedPathname;
  444. Time fileTime;
  445. int64 compressedSize = 0, uncompressedSize = 0, headerStart = 0;
  446. int compressionLevel = 0;
  447. unsigned long checksum = 0;
  448. bool symbolicLink = false;
  449. static void writeTimeAndDate (OutputStream& target, Time t)
  450. {
  451. target.writeShort ((short) (t.getSeconds() + (t.getMinutes() << 5) + (t.getHours() << 11)));
  452. target.writeShort ((short) (t.getDayOfMonth() + ((t.getMonth() + 1) << 5) + ((t.getYear() - 1980) << 9)));
  453. }
  454. bool writeSource (OutputStream& target)
  455. {
  456. if (stream == nullptr)
  457. {
  458. stream = file.createInputStream();
  459. if (stream == nullptr)
  460. return false;
  461. }
  462. checksum = 0;
  463. uncompressedSize = 0;
  464. const int bufferSize = 4096;
  465. HeapBlock<unsigned char> buffer (bufferSize);
  466. while (! stream->isExhausted())
  467. {
  468. auto bytesRead = stream->read (buffer, bufferSize);
  469. if (bytesRead < 0)
  470. return false;
  471. checksum = zlibNamespace::crc32 (checksum, buffer, (unsigned int) bytesRead);
  472. target.write (buffer, (size_t) bytesRead);
  473. uncompressedSize += bytesRead;
  474. }
  475. stream.reset();
  476. return true;
  477. }
  478. void writeFlagsAndSizes (OutputStream& target) const
  479. {
  480. target.writeShort (10); // version needed
  481. target.writeShort ((short) (1 << 11)); // this flag indicates UTF-8 filename encoding
  482. target.writeShort ((! symbolicLink && compressionLevel > 0) ? (short) 8 : (short) 0); //symlink target path is not compressed
  483. writeTimeAndDate (target, fileTime);
  484. target.writeInt ((int) checksum);
  485. target.writeInt ((int) (uint32) compressedSize);
  486. target.writeInt ((int) (uint32) uncompressedSize);
  487. target.writeShort (static_cast<short> (storedPathname.toUTF8().sizeInBytes() - 1));
  488. target.writeShort (0); // extra field length
  489. }
  490. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Item)
  491. };
  492. //==============================================================================
  493. ZipFile::Builder::Builder() {}
  494. ZipFile::Builder::~Builder() {}
  495. void ZipFile::Builder::addFile (const File& file, int compression, const String& path)
  496. {
  497. items.add (new Item (file, nullptr, compression,
  498. path.isEmpty() ? file.getFileName() : path,
  499. file.getLastModificationTime()));
  500. }
  501. void ZipFile::Builder::addEntry (InputStream* stream, int compression, const String& path, Time time)
  502. {
  503. jassert (stream != nullptr); // must not be null!
  504. jassert (path.isNotEmpty());
  505. items.add (new Item ({}, stream, compression, path, time));
  506. }
  507. bool ZipFile::Builder::writeToStream (OutputStream& target, double* const progress) const
  508. {
  509. auto fileStart = target.getPosition();
  510. for (int i = 0; i < items.size(); ++i)
  511. {
  512. if (progress != nullptr)
  513. *progress = (i + 0.5) / items.size();
  514. if (! items.getUnchecked (i)->writeData (target, fileStart))
  515. return false;
  516. }
  517. auto directoryStart = target.getPosition();
  518. for (auto* item : items)
  519. if (! item->writeDirectoryEntry (target))
  520. return false;
  521. auto directoryEnd = target.getPosition();
  522. target.writeInt (0x06054b50);
  523. target.writeShort (0);
  524. target.writeShort (0);
  525. target.writeShort ((short) items.size());
  526. target.writeShort ((short) items.size());
  527. target.writeInt ((int) (directoryEnd - directoryStart));
  528. target.writeInt ((int) (directoryStart - fileStart));
  529. target.writeShort (0);
  530. if (progress != nullptr)
  531. *progress = 1.0;
  532. return true;
  533. }
  534. //==============================================================================
  535. //==============================================================================
  536. #if JUCE_UNIT_TESTS
  537. struct ZIPTests final : public UnitTest
  538. {
  539. ZIPTests()
  540. : UnitTest ("ZIP", UnitTestCategories::compression)
  541. {}
  542. static MemoryBlock createZipMemoryBlock (const StringArray& entryNames)
  543. {
  544. ZipFile::Builder builder;
  545. HashMap<String, MemoryBlock> blocks;
  546. for (auto& entryName : entryNames)
  547. {
  548. auto& block = blocks.getReference (entryName);
  549. MemoryOutputStream mo (block, false);
  550. mo << entryName;
  551. mo.flush();
  552. builder.addEntry (new MemoryInputStream (block, false), 9, entryName, Time::getCurrentTime());
  553. }
  554. MemoryBlock data;
  555. MemoryOutputStream mo (data, false);
  556. builder.writeToStream (mo, nullptr);
  557. return data;
  558. }
  559. void runZipSlipTest()
  560. {
  561. const std::map<String, bool> testCases = { { "a", true },
  562. #if JUCE_WINDOWS
  563. { "C:/b", false },
  564. #else
  565. { "/b", false },
  566. #endif
  567. { "c/d", true },
  568. { "../e/f", false },
  569. { "../../g/h", false },
  570. { "i/../j", true },
  571. { "k/l/../", true },
  572. { "m/n/../../", false },
  573. { "o/p/../../../", false } };
  574. StringArray entryNames;
  575. for (const auto& testCase : testCases)
  576. entryNames.add (testCase.first);
  577. TemporaryFile tmpDir;
  578. tmpDir.getFile().createDirectory();
  579. auto data = createZipMemoryBlock (entryNames);
  580. MemoryInputStream mi (data, false);
  581. ZipFile zip (mi);
  582. for (int i = 0; i < zip.getNumEntries(); ++i)
  583. {
  584. const auto result = zip.uncompressEntry (i, tmpDir.getFile());
  585. const auto caseIt = testCases.find (zip.getEntry (i)->filename);
  586. if (caseIt != testCases.end())
  587. {
  588. expect (result.wasOk() == caseIt->second,
  589. zip.getEntry (i)->filename + " was unexpectedly " + (result.wasOk() ? "OK" : "not OK"));
  590. }
  591. else
  592. {
  593. expect (false);
  594. }
  595. }
  596. }
  597. void runTest() override
  598. {
  599. beginTest ("ZIP");
  600. StringArray entryNames { "first", "second", "third" };
  601. auto data = createZipMemoryBlock (entryNames);
  602. MemoryInputStream mi (data, false);
  603. ZipFile zip (mi);
  604. expectEquals (zip.getNumEntries(), entryNames.size());
  605. for (auto& entryName : entryNames)
  606. {
  607. auto* entry = zip.getEntry (entryName);
  608. std::unique_ptr<InputStream> input (zip.createStreamForEntry (*entry));
  609. expectEquals (input->readEntireStreamAsString(), entryName);
  610. }
  611. beginTest ("ZipSlip");
  612. runZipSlipTest();
  613. }
  614. };
  615. static ZIPTests zipTests;
  616. #endif
  617. } // namespace juce