From 7a2c06a8a577a190230a3f87863be241d13ee86a Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Thu, 5 Jul 2012 15:40:29 +0200
Subject: [PATCH] OO-295: catch the error generated by a ZIP with the wrong
 encoding

---
 .../commons/modules/bc/commands/CmdUnzip.java | 35 +++++++++++--------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/olat/core/commons/modules/bc/commands/CmdUnzip.java b/src/main/java/org/olat/core/commons/modules/bc/commands/CmdUnzip.java
index 39b11f54c23..e23c0469606 100644
--- a/src/main/java/org/olat/core/commons/modules/bc/commands/CmdUnzip.java
+++ b/src/main/java/org/olat/core/commons/modules/bc/commands/CmdUnzip.java
@@ -95,23 +95,30 @@ public class CmdUnzip extends BasicController implements FolderCommand {
 			return null;
 		}
 		
-		boolean fileNotExist = false;
-		for (String sItem:selection.getFiles()) {
-			VFSItem vfsItem = currentContainer.resolve(sItem);
-			if (vfsItem != null && (vfsItem instanceof VFSLeaf)) {
-				if (!doUnzip((VFSLeaf)vfsItem, currentContainer, ureq, wContr)) {
-					status = FolderCommandStatus.STATUS_FAILED;
+		VFSItem currentVfsItem = null;
+		try {
+			boolean fileNotExist = false;
+			for (String sItem:selection.getFiles()) {
+				currentVfsItem = currentContainer.resolve(sItem);
+				if (currentVfsItem != null && (currentVfsItem instanceof VFSLeaf)) {
+					if (!doUnzip((VFSLeaf)currentVfsItem, currentContainer, ureq, wContr)) {
+						status = FolderCommandStatus.STATUS_FAILED;
+						break;
+					}
+				} else {
+					fileNotExist = true;
 					break;
 				}
-			} else {
-				fileNotExist = true;
-				break;
 			}
-		}
-		
-		if (fileNotExist) {
-			status = FolderCommandStatus.STATUS_FAILED;
-			getWindowControl().setError(translator.translate("FileDoesNotExist"));
+			
+			if (fileNotExist) {
+				status = FolderCommandStatus.STATUS_FAILED;
+				getWindowControl().setError(translator.translate("FileDoesNotExist"));
+			}
+		} catch (IllegalArgumentException e) {
+			logError("Corrupted ZIP", e);
+			String name = currentVfsItem == null ? "NULL" : currentVfsItem.getName();
+			getWindowControl().setError(translator.translate("FileUnzipFailed", new String[]{name}));
 		}
 		
 		return null;
-- 
GitLab