diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index ae81f35eb41d61a8426a827b0f11f59f8ebfbd1c..c7b389d8db93e970cacd78d0510655f7b6c95786 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -1198,6 +1198,26 @@ public class Compressor { return true; } + private boolean checkFastAppUbsanValid(String modulePath) throws BundleException { + try { + String jsonPath = modulePath + File.separator + "module.json"; + Optional optional = FileUtils.getFileContent(jsonPath); + if (optional.isPresent()) { + String jsonString = optional.get(); + boolean hwasanEnabled = ModuleJsonUtil.getStageHwasanEnabled(jsonString); + boolean ubsanEnabled = ModuleJsonUtil.getStageUbsanEnabled(jsonString); + if (ubsanEnabled && hwasanEnabled) { + LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString( + "ubsanEnabled and hwasanEnabled cannot be true at the same time.")); + return false; + } + } + } catch (Exception e) { + LOG.warning("Failed to check ubsan for module: " + modulePath + ", error: " + e.getMessage()); + } + return true; + } + private static boolean checkStageAtomicService(String jsonString) throws BundleException { // check consistency of atomicService if (!ModuleJsonUtil.isModuleAtomicServiceValid(jsonString)) { @@ -1653,6 +1673,16 @@ public class Compressor { tmpDir = Files.createTempDirectory(appOutPath.getParent(), TEMP_DIR); Path appPackInfo = Paths.get(utility.getPackInfoPath()); List fileList = new ArrayList<>(); + for (String hapPath : utility.getFormattedHapPathList()) { + if (!checkFastAppUbsanValid(hapPath)) { + throw new BundleException("ubsan validation failed for HAP: " + hapPath); + } + } + for (String hspPath : utility.getFormattedHspPathList()) { + if (!checkFastAppUbsanValid(hspPath)) { + throw new BundleException("ubsan validation failed for HSP: " + hspPath); + } + } for (String hapPath : utility.getFormattedHapPathList()) { Path path = Paths.get(hapPath); Path hap = PackageUtil.pack(path, appPackInfo, tmpDir, utility.getCompressLevel());