You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by bc...@apache.org on 2023/11/04 00:09:39 UTC

(incubator-baremaps) branch 790-file-exists updated (6c2dc496 -> 95dba61a)

This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a change to branch 790-file-exists
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git


 discard 6c2dc496 Fix unzip task and add shaded relief workflow
     new 95dba61a Fix unzip task and add shaded relief workflow

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (6c2dc496)
            \
             N -- N -- N   refs/heads/790-file-exists (95dba61a)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/main/java/org/apache/baremaps/workflow/tasks/UnzipFile.java    | 3 ---
 examples/shadedrelief/workflow.json                                    | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)


(incubator-baremaps) 01/01: Fix unzip task and add shaded relief workflow

Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch 790-file-exists
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit 95dba61a756381e563907ff5e98a38c0b00045f5
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Sat Nov 4 00:46:00 2023 +0100

    Fix unzip task and add shaded relief workflow
    
    The unzip task implemented some checks against malicious
    zip files that failed with the shaded relief archive.
    They have now been removed.
---
 ...reate.run.xml => naturalearth-workflow.run.xml} |  7 ++++-
 .../apache/baremaps/workflow/tasks/UnzipFile.java  | 36 +++-------------------
 examples/shadedrelief/workflow.json                | 20 ++++++++++++
 3 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/.run/naturalearth-create.run.xml b/.run/naturalearth-workflow.run.xml
similarity index 54%
rename from .run/naturalearth-create.run.xml
rename to .run/naturalearth-workflow.run.xml
index fb309124..45f5277d 100644
--- a/.run/naturalearth-create.run.xml
+++ b/.run/naturalearth-workflow.run.xml
@@ -1,9 +1,14 @@
 <component name="ProjectRunConfigurationManager">
-  <configuration default="false" name="naturalearth-create" type="Application" factoryName="Application">
+  <configuration default="false" name="naturalearth-workflow" type="Application" factoryName="Application">
     <option name="MAIN_CLASS_NAME" value="org.apache.baremaps.cli.Baremaps" />
     <module name="baremaps-cli" />
     <option name="PROGRAM_PARAMETERS" value="workflow execute --file workflow.json" />
     <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/naturalearth" />
+    <extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension">
+      <option name="credential" />
+      <option name="region" />
+      <option name="useCurrentConnection" value="false" />
+    </extension>
     <method v="2">
       <option name="Make" enabled="true" />
     </method>
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UnzipFile.java b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UnzipFile.java
index 5a1181d9..dc89d9c5 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UnzipFile.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UnzipFile.java
@@ -22,18 +22,9 @@ import java.nio.file.*;
 import java.util.zip.ZipFile;
 import org.apache.baremaps.workflow.Task;
 import org.apache.baremaps.workflow.WorkflowContext;
-import org.apache.baremaps.workflow.WorkflowException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public record UnzipFile(Path file, Path directory) implements Task {
 
-  private static final long THRESHOLD_ENTRIES = 10000;
-  private static final long THRESHOLD_SIZE = 10l << 30;
-  private static final double THRESHOLD_RATIO = 100;
-
-  private static final Logger logger = LoggerFactory.getLogger(UnzipFile.class);
-
   @Override
   public void execute(WorkflowContext context) throws Exception {
     var filePath = file.toAbsolutePath();
@@ -41,11 +32,13 @@ public record UnzipFile(Path file, Path directory) implements Task {
 
     try (var zipFile = new ZipFile(filePath.toFile())) {
       var entries = zipFile.entries();
-      long totalSizeArchive = 0;
-      long totalEntryArchive = 0;
 
       while (entries.hasMoreElements()) {
         var ze = entries.nextElement();
+        if (ze.isDirectory()) {
+          continue;
+        }
+
         var path = directoryPath.resolve(ze.getName());
 
         var file = path.toFile().getCanonicalFile();
@@ -61,29 +54,10 @@ public record UnzipFile(Path file, Path directory) implements Task {
         try (var input = new BufferedInputStream(zipFile.getInputStream(ze));
             var output = new BufferedOutputStream(new FileOutputStream(path.toFile()))) {
 
-          totalEntryArchive++;
-
-          int nBytes = -1;
+          int nBytes;
           byte[] buffer = new byte[4096];
-          long totalSizeEntry = 0;
-
           while ((nBytes = input.read(buffer)) > 0) {
             output.write(buffer, 0, nBytes);
-            totalSizeEntry += nBytes;
-            totalSizeArchive += nBytes;
-
-            double compressionRatio = (double) totalSizeEntry / (double) ze.getCompressedSize();
-            if (compressionRatio > THRESHOLD_RATIO) {
-              throw new WorkflowException("Archive compression ratio is too high");
-            }
-          }
-
-          if (totalSizeArchive > THRESHOLD_SIZE) {
-            throw new IOException("Archive is too large");
-          }
-
-          if (totalEntryArchive > THRESHOLD_ENTRIES) {
-            throw new IOException("Archive contains too many entries");
           }
         }
       }
diff --git a/examples/shadedrelief/workflow.json b/examples/shadedrelief/workflow.json
new file mode 100644
index 00000000..48407d52
--- /dev/null
+++ b/examples/shadedrelief/workflow.json
@@ -0,0 +1,20 @@
+{
+  "steps": [
+    {
+      "id": "natural-earth",
+      "needs": [],
+      "tasks": [
+        {
+          "type": "DownloadUrl",
+          "url": "http://www.shadedrelief.com/ne-draft/World-Base-Map-Shapefiles.zip",
+          "path": "shadedrelief.zip"
+        },
+        {
+          "type": "UnzipFile",
+          "file": "shadedrelief.zip",
+          "directory": "shadedrelief"
+        }
+      ]
+    }
+  ]
+}