修复流的方法错误 ,修复跨域脚本缺少BASE64 (#423)

* 修复office下载方法中 错误

* 更新OFD解析效果,修复禁止trace请求无效问题,其他压缩包修复

* 修复压缩包 缓存BUG

* 限制某些特殊文件上传

* 修复OFFICE文件密码检查关闭流 上传文件关闭流 检查PDF文件是否存在

* 特殊符号的支持

Co-authored-by: gaoxiongzaq <admin@cxcp.com>
This commit is contained in:
gaoxingzaq
2023-01-11 13:26:18 +08:00
committed by GitHub
parent 04401ee600
commit 5dc543db99
16 changed files with 918 additions and 752 deletions

View File

@@ -7,6 +7,7 @@ import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.springframework.lang.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -27,8 +28,10 @@ public class OfficeUtils {
* @return 是否受密码保护
*/
public static boolean isPwdProtected(String path) {
InputStream propStream = null;
try {
ExtractorFactory.createExtractor(Files.newInputStream(Paths.get(path)));
propStream = Files.newInputStream(Paths.get(path));
ExtractorFactory.createExtractor(propStream);
} catch (IOException | EncryptedDocumentException e) {
if (e.getMessage().toLowerCase().contains(POI_INVALID_PASSWORD_MSG)) {
return true;
@@ -42,10 +45,17 @@ public class OfficeUtils {
}
}
}
}finally {
if(propStream!=null) {//如果文件输入流不是null
try {
propStream.close();//关闭文件输入流
} catch (IOException e) {
e.printStackTrace();
}
}
}
return false;
}
/**
* 判断office文件是否可打开兼容
*
@@ -54,15 +64,24 @@ public class OfficeUtils {
* @return 是否可打开(兼容)
*/
public static synchronized boolean isCompatible(String path, @Nullable String password) {
InputStream propStream = null;
try {
propStream = Files.newInputStream(Paths.get(path));
Biff8EncryptionKey.setCurrentUserPassword(password);
ExtractorFactory.createExtractor(Files.newInputStream(Paths.get(path)));
ExtractorFactory.createExtractor(propStream);
} catch (Exception e) {
return false;
} finally {
Biff8EncryptionKey.setCurrentUserPassword(null);
if(propStream!=null) {//如果文件输入流不是null
try {
propStream.close();//关闭文件输入流
} catch (IOException e) {
e.printStackTrace();
}
}
}
return true;
}
}
}