관리 메뉴

ふたりで

Failed to read zip entry source, Zip bomb detected! 해결 방법 본문

JAVA

Failed to read zip entry source, Zip bomb detected! 해결 방법

graykang 2023. 11. 15. 15:25
728x90
반응형
SMALL

apache.poi.xssf.streaming.SXSSFWorkbook 을 사용하여 엑셀 파일을 생성할 때 row수가 290개 이상일 때

아래와 같은 에러가 발생을 했다.

java.io.IOException: Failed to read zip entry source
	at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:103)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:324)
	at com.togethers.b2b.common.util.POIUtil.makeExcel(POIUtil.java:159)
	at com.togethers.b2b.controller.OrderController.excelOrderListForInvoice(OrderController.java:1122)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
.
.
.
생략
.
.
.
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1784)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:750)
Caused by: java.io.IOException: Zip bomb detected! The file would exceed the max. ratio of compressed file size to the size of the expanded data. This may indicate that the file is used to inflate memory usage and thus could pose a security risk. You can adjust this limit via ZipSecureFile.setMinInflateRatio() if you need to work with files which exceed this limit. Counter: 400224, cis.counter: 3997, ratio: 0.009986907331894139Limits: MIN_INFLATE_RATIO: 0.01
	at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.advance(ZipSecureFile.java:266)
	at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.read(ZipSecureFile.java:221)
	at java.io.FilterInputStream.read(FilterInputStream.java:107)
	at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource$FakeZipEntry.<init>(ZipInputStreamZipEntrySource.java:132)
	at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.<init>(ZipInputStreamZipEntrySource.java:56)
	at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:100)

아래는 위의 Error 메시지 중 Caused by : 부분을 구글 번역한 내용이다.

원인: java.io.IOException: Zip 폭탄이 감지되었습니다! 파일이 최대값을 초과합니다. 
압축된 파일 크기와 확장된 데이터 크기의 비율입니다. 
이는 파일이 메모리 사용량을 늘리는 데 사용되어 보안 위험을 초래할 수 있음을 나타낼 수 있습니다. 
이 제한을 초과하는 파일로 작업해야 하는 경우 ZipSecureFile.setMinInflateRatio()를 통해 
이 제한을 조정할 수 있습니다. 
카운터: 400224, cis.counter: 3997, 비율: 0.009986907331894139한계: MIN_INFLATE_RATIO: 0.01

 

간략히 보자면 Failed to read zip entry source, Zip bomb detected! 두 가지 에러 메시지를 확인할 수 있고 관련하여 구글링

을 한 결과 아래와 같이 SXSSFWorkbook 사용하여 엑셀 파일을 읽을 때 옵션 값을 설정하면 해결할 수 있다는 정보를 얻었다.

해당 옵션은 apache.poi에서 보안 차원에서 걸어놓은 제약 조건을 해제하는 옵션이다.

내가 아닌 다른 사람이 생성한 엑셀 파일일 경우 옵션을 어떻게 조정 할지는 좀 더 알아봐야 하지만,

내가 생성한 엑셀 파일에 악의적인 코드가 들어갈 일은 없기에 해당 옵션을 해제 처리 해서 사용해도 무방 할 것 같다.

        	workbook = new SXSSFWorkbook();
        	ZipSecureFile.setMinInflateRatio(0);// Zip bomb detected!해재 옵션    	
        	sheet = workbook.createSheet(sheetName);

 

출처:

https://stackoverflow.com/questions/44897500/using-apache-poi-zip-bomb-detected

 

Using Apache POI - Zip Bomb detected

When I am trying to write data to an Excel sheet, using Apache POI which contains more than 64000 records, where SXSSF is used, I am getting the below error: Zip bomb detected! The file would exce...

stackoverflow.com

 

728x90
반응형
LIST
Comments