forked from floraachy/ImageKnife
使用安全函数memset_s替代memset,memcpy_s替代memcpy
Signed-off-by: liuhaikang <liuhaikang@huawei-partners.com>
This commit is contained in:
parent
95a2526408
commit
46b75226cf
|
@ -0,0 +1,3 @@
|
|||
[submodule "gpu_transform/src/main/cpp/boundscheck/third_party_bounds_checking_function"]
|
||||
path = gpu_transform/src/main/cpp/boundscheck/third_party_bounds_checking_function
|
||||
url = https://gitee.com/openharmony/third_party_bounds_checking_function.git
|
2
OAT.xml
2
OAT.xml
|
@ -28,6 +28,7 @@
|
|||
<filteritem type="filename" name="hvigorw.bat" desc="hvigorw配置文件,DevEco Studio自动生成,不手动修改"/>
|
||||
<filteritem type="filename" name="hvigor-wrapper.js" desc="hvigorw配置文件,DevEco Studio自动生成,不手动修改"/>
|
||||
<filteritem type="filepath" name="library/src/main/ets/components/3rd_party/.*" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
|
||||
<filteritem type="filename" name=".gitmodules" desc="项目工程配置文件,不需要添加版权头"/>
|
||||
</filefilter>
|
||||
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
|
||||
<filteritem type="filename" name="hvigorfile.*" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
|
||||
|
@ -38,6 +39,7 @@
|
|||
<filteritem type="filename" name="hvigorw.bat" desc="hvigorw配置文件,DevEco Studio自动生成,不手动修改"/>
|
||||
<filteritem type="filename" name="hvigor-wrapper.js" desc="hvigorw配置文件,DevEco Studio自动生成,不手动修改"/>
|
||||
<filteritem type="filepath" name="library/src/main/ets/components/3rd_party/.*" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
|
||||
<filteritem type="filename" name=".gitmodules" desc="项目工程配置文件,不需要添加版权头"/>
|
||||
</filefilter>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
|
||||
<filteritem type="filename" name="*.dpg" desc="dpg图片格式文件,用于展示示例"/>
|
||||
|
|
|
@ -11,8 +11,11 @@ include_directories(${NATIVERENDER_ROOT_PATH}
|
|||
${NATIVERENDER_ROOT_PATH}/common
|
||||
${NATIVERENDER_ROOT_PATH}/render
|
||||
${NATIVERENDER_ROOT_PATH}/constant
|
||||
${NATIVERENDER_ROOT_PATH}/boundscheck
|
||||
)
|
||||
|
||||
add_subdirectory(boundscheck)
|
||||
|
||||
add_library(nativeGpu SHARED
|
||||
${NATIVERENDER_ROOT_PATH}/napi/napi_init.cpp
|
||||
${NATIVERENDER_ROOT_PATH}/render/EGLRender.cpp
|
||||
|
@ -30,4 +33,4 @@ find_library (
|
|||
GLES-lib
|
||||
GLESv3 )
|
||||
|
||||
target_link_libraries(nativeGpu PUBLIC ${hilog-lib} ${EGL-lib} ${GLES-lib} libace_napi.z.so libc++.a -s -ftrapv)
|
||||
target_link_libraries(nativeGpu PUBLIC boundscheck ${hilog-lib} ${EGL-lib} ${GLES-lib} libace_napi.z.so -s -ftrapv)
|
|
@ -0,0 +1,25 @@
|
|||
# the minimum version of CMake.
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
|
||||
set(can_use_assembler TRUE)
|
||||
enable_language(ASM)
|
||||
IF("${OHOS_ARCH}" STREQUAL "arm64-v8a")
|
||||
SET(ASM_OPTIONS "-x assembler-with-cpp")
|
||||
SET(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS} -march=armv8+crypto -D__OHOS__")
|
||||
ENDIF()
|
||||
|
||||
project(boundscheck)
|
||||
|
||||
set(TAGET_BOUNDSCHECK_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/third_party_bounds_checking_function/src)
|
||||
|
||||
add_library(boundscheck
|
||||
STATIC
|
||||
${TAGET_BOUNDSCHECK_SRC_PATH}/memcpy_s.c
|
||||
${TAGET_BOUNDSCHECK_SRC_PATH}/memset_s.c
|
||||
${TAGET_BOUNDSCHECK_SRC_PATH}/securecutil.c)
|
||||
|
||||
include_directories(${TAGET_BOUNDSCHECK_SRC_PATH}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/third_party_bounds_checking_function/include
|
||||
)
|
||||
|
||||
target_link_libraries(boundscheck)
|
|
@ -0,0 +1 @@
|
|||
Subproject commit a45b3aceed2c0138babc951850445d1cd010ce48
|
|
@ -535,7 +535,10 @@ void EGLRender::SetImageData(uint8_t *pData, int width, int height)
|
|||
m_RenderImage.height = height;
|
||||
m_RenderImage.format = IMAGE_FORMAT_RGBA;
|
||||
NativeImageUtil::AllocNativeImage(&m_RenderImage);
|
||||
memcpy(m_RenderImage.ppPlane[0], pData, width * height * DEFAULT_FOUR);
|
||||
if (memcpy_s(m_RenderImage.ppPlane[0],
|
||||
width * height * DEFAULT_FOUR, pData, width * height * DEFAULT_FOUR) != EOK) {
|
||||
return;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, m_ImageTextureId);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <string>
|
||||
#include <string.h>
|
||||
#include "DebugLog.h"
|
||||
#include "third_party_bounds_checking_function/include/securec.h"
|
||||
|
||||
const int32_t MAX_STR_LENGTH = 1024;
|
||||
|
||||
|
@ -41,7 +42,7 @@ void NapiUtil::JsValueToString(const napi_env &env, const napi_value &value, con
|
|||
LOGI("%s nullptr js object to string malloc failed", __func__);
|
||||
return;
|
||||
}
|
||||
(void) memset(buf.get(), 0, bufLen);
|
||||
(void) memset_s(buf.get(), bufLen, 0, bufLen);
|
||||
size_t result = 0;
|
||||
napi_get_value_string_utf8(env, value, buf.get(), bufLen, &result);
|
||||
target = buf.get();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <string.h>
|
||||
#include "DebugLog.h"
|
||||
#include "constant/constant_shape.h"
|
||||
#include "third_party_bounds_checking_function/include/securec.h"
|
||||
|
||||
#define IMAGE_FORMAT_RGBA 0x01
|
||||
#define IMAGE_FORMAT_NV21 0x02
|
||||
|
@ -48,7 +49,7 @@
|
|||
#define IMAGE_FORMAT_GRAY_EXT "GRAY"
|
||||
#define IMAGE_FORMAT_I444_EXT "I444"
|
||||
#define IMAGE_FORMAT_P010_EXT "P010" // 16bit NV21
|
||||
|
||||
#define EOK 0
|
||||
|
||||
struct NativeImage {
|
||||
int width;
|
||||
|
@ -140,7 +141,9 @@ public:
|
|||
if (napi_create_arraybuffer(env, srcLen, &nativePtr, res) != napi_ok || nativePtr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
memcpy(nativePtr, src, srcLen);
|
||||
if (memcpy_s(nativePtr, srcLen, src, srcLen) != EOK) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -149,10 +152,17 @@ public:
|
|||
int totalLength = width * height * DEFAULT_FOUR;
|
||||
int oneLineLength = width * DEFAULT_FOUR;
|
||||
uint8_t* tmp = (uint8_t*)malloc(totalLength);
|
||||
memcpy(tmp, *buf, totalLength);
|
||||
memset(*buf, DEFAULT_ZERO, sizeof(uint8_t)*totalLength);
|
||||
if (memcpy_s(tmp, totalLength, *buf, totalLength) != EOK) {
|
||||
return;
|
||||
}
|
||||
if (memset_s(*buf, sizeof(uint8_t)*totalLength, DEFAULT_ZERO, sizeof(uint8_t)*totalLength) != EOK) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < height; i++) {
|
||||
memcpy(*buf + oneLineLength * i, tmp + totalLength - oneLineLength * (i+1), oneLineLength);
|
||||
if (memcpy_s(*buf + oneLineLength * i, oneLineLength,
|
||||
tmp + totalLength - oneLineLength * (i+1), oneLineLength) != EOK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(tmp);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue