Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Harfbuzz
提交
98daaf18
T
Third Party Harfbuzz
项目概览
OpenHarmony
/
Third Party Harfbuzz
接近 2 年 前同步成功
通知
1
Star
18
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Harfbuzz
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
98daaf18
编写于
5月 04, 2010
作者:
B
Behdad Esfahbod
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make _hb_sanitize_*() methods of the context object
上级
bb029af9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
98 addition
and
92 deletion
+98
-92
src/hb-open-type-private.hh
src/hb-open-type-private.hh
+98
-92
未找到文件。
src/hb-open-type-private.hh
浏览文件 @
98daaf18
...
...
@@ -137,95 +137,101 @@ ASSERT_STATIC (sizeof (Type) + 1 <= sizeof (_Null##Type))
struct
hb_sanitize_context_t
{
const
char
*
start
,
*
end
;
hb_bool_t
writable
;
unsigned
int
edit_count
;
};
inline
void
init
(
hb_blob_t
*
blob
)
{
this
->
blob
=
hb_blob_reference
(
blob
);
this
->
start
=
hb_blob_lock
(
blob
);
this
->
end
=
this
->
start
+
hb_blob_get_length
(
blob
);
this
->
writable
=
hb_blob_is_writable
(
blob
);
this
->
edit_count
=
0
;
if
(
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"sanitize %p init [%p..%p] (%u bytes)
\n
"
,
this
->
blob
,
this
->
start
,
this
->
end
,
this
->
end
-
this
->
start
);
}
static
inline
void
_hb_sanitize_init
(
hb_sanitize_context_t
*
context
,
hb_blob_t
*
blob
)
{
context
->
start
=
hb_blob_lock
(
blob
);
context
->
end
=
context
->
start
+
hb_blob_get_length
(
blob
);
context
->
writable
=
hb_blob_is_writable
(
blob
);
context
->
edit_count
=
0
;
if
(
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"sanitize %p init [%p..%p] (%u bytes)
\n
"
,
blob
,
context
->
start
,
context
->
end
,
context
->
end
-
context
->
start
);
}
inline
void
finish
(
void
)
{
if
(
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"sanitize %p fini [%p..%p] %u edit requests
\n
"
,
this
->
blob
,
this
->
start
,
this
->
end
,
this
->
edit_count
);
static
inline
void
_hb_sanitize_fini
(
hb_sanitize_context_t
*
context
HB_UNUSED
,
hb_blob_t
*
blob
)
{
if
(
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"sanitize %p fini [%p..%p] %u edit requests
\n
"
,
blob
,
context
->
start
,
context
->
end
,
context
->
edit_count
);
hb_blob_unlock
(
this
->
blob
);
hb_blob_destroy
(
this
->
blob
);
this
->
blob
=
NULL
;
this
->
start
=
this
->
end
=
NULL
;
}
hb_blob_unlock
(
blob
);
}
inline
bool
check
(
unsigned
int
sanitize_depth
,
const
char
*
base
,
unsigned
int
len
)
const
{
bool
ret
=
this
->
start
<=
base
&&
base
<=
this
->
end
&&
(
unsigned
int
)
(
this
->
end
-
base
)
>=
len
;
if
(
HB_DEBUG_SANITIZE
&&
(
int
)
sanitize_depth
<
(
int
)
HB_DEBUG_SANITIZE
)
\
fprintf
(
stderr
,
"SANITIZE(%p) %-*d-> check [%p..%p] (%d bytes) in [%p..%p] -> %s
\n
"
,
\
base
,
sanitize_depth
,
sanitize_depth
,
base
,
base
+
len
,
len
,
this
->
start
,
this
->
end
,
ret
?
"pass"
:
"FAIL"
);
return
ret
;
}
static
inline
bool
_hb_sanitize_check
(
SANITIZE_ARG_DEF
,
const
char
*
base
,
unsigned
int
len
)
{
bool
ret
=
context
->
start
<=
base
&&
base
<=
context
->
end
&&
(
unsigned
int
)
(
context
->
end
-
base
)
>=
len
;
if
(
HB_DEBUG_SANITIZE
&&
(
int
)
sanitize_depth
<
(
int
)
HB_DEBUG_SANITIZE
)
\
fprintf
(
stderr
,
"SANITIZE(%p) %-*d-> check [%p..%p] (%d bytes) in [%p..%p] -> %s
\n
"
,
\
base
,
sanitize_depth
,
sanitize_depth
,
base
,
base
+
len
,
len
,
context
->
start
,
context
->
end
,
ret
?
"pass"
:
"FAIL"
);
return
ret
;
}
inline
bool
check_array
(
unsigned
int
sanitize_depth
,
const
char
*
base
,
unsigned
int
record_size
,
unsigned
int
len
)
const
{
bool
overflows
=
len
>=
((
unsigned
int
)
-
1
)
/
record_size
;
static
inline
bool
_hb_sanitize_array
(
SANITIZE_ARG_DEF
,
const
char
*
base
,
unsigned
int
record_size
,
unsigned
int
len
)
{
bool
overflows
=
len
>=
((
unsigned
int
)
-
1
)
/
record_size
;
if
(
HB_DEBUG_SANITIZE
&&
(
int
)
sanitize_depth
<
(
int
)
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"SANITIZE(%p) %-*d-> array [%p..%p] (%d*%d=%ld bytes) in [%p..%p] -> %s
\n
"
,
\
base
,
sanitize_depth
,
sanitize_depth
,
base
,
base
+
(
record_size
*
len
),
record_size
,
len
,
(
unsigned
long
)
record_size
*
len
,
this
->
start
,
this
->
end
,
!
overflows
?
"does not overflow"
:
"OVERFLOWS FAIL"
);
if
(
HB_DEBUG_SANITIZE
&&
(
int
)
sanitize_depth
<
(
int
)
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"SANITIZE(%p) %-*d-> array [%p..%p] (%d*%d=%ld bytes) in [%p..%p] -> %s
\n
"
,
\
base
,
sanitize_depth
,
sanitize_depth
,
base
,
base
+
(
record_size
*
len
),
record_size
,
len
,
(
unsigned
long
)
record_size
*
len
,
context
->
start
,
context
->
end
,
!
overflows
?
"does not overflow"
:
"OVERFLOWS FAIL"
);
return
likely
(
!
overflows
)
&&
this
->
check
(
sanitize_depth
,
base
,
record_size
*
len
);
}
return
likely
(
!
overflows
)
&&
_hb_sanitize_check
(
SANITIZE_ARG
,
base
,
record_size
*
len
);
}
inline
bool
can_edit
(
unsigned
int
sanitize_depth
,
const
char
*
base
HB_UNUSED
,
unsigned
int
len
HB_UNUSED
)
{
this
->
edit_count
++
;
if
(
HB_DEBUG_SANITIZE
&&
(
int
)
sanitize_depth
<
(
int
)
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"SANITIZE(%p) %-*d-> edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s
\n
"
,
\
base
,
sanitize_depth
,
sanitize_depth
,
this
->
edit_count
,
base
,
base
+
len
,
len
,
this
->
start
,
this
->
end
,
this
->
writable
?
"granted"
:
"REJECTED"
);
return
this
->
writable
;
}
inline
const
char
*
get_start
(
void
)
const
{
return
start
;
}
inline
const
char
*
get_end
(
void
)
const
{
return
end
;
}
inline
bool
is_writable
(
void
)
const
{
return
writable
;
}
inline
unsigned
int
get_edit_count
(
void
)
const
{
return
this
->
edit_count
;
}
inline
void
reset_edit_count
(
void
)
{
this
->
edit_count
=
0
;
}
private:
const
char
*
start
,
*
end
;
bool
writable
;
unsigned
int
edit_count
;
hb_blob_t
*
blob
;
};
static
inline
bool
_hb_sanitize_edit
(
SANITIZE_ARG_DEF
,
const
char
*
base
HB_UNUSED
,
unsigned
int
len
HB_UNUSED
)
{
context
->
edit_count
++
;
if
(
HB_DEBUG_SANITIZE
&&
(
int
)
sanitize_depth
<
(
int
)
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"SANITIZE(%p) %-*d-> edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s
\n
"
,
\
base
,
sanitize_depth
,
sanitize_depth
,
context
->
edit_count
,
base
,
base
+
len
,
len
,
context
->
start
,
context
->
end
,
context
->
writable
?
"granted"
:
"REJECTED"
);
return
context
->
writable
;
}
#define SANITIZE(X) likely ((X).sanitize (SANITIZE_ARG))
...
...
@@ -233,9 +239,9 @@ _hb_sanitize_edit (SANITIZE_ARG_DEF,
#define SANITIZE_SELF() SANITIZE_MEM(this, sizeof (*this))
#define SANITIZE_MEM(B,L) likely (
_hb_sanitize_check (SANITIZE_ARG
, CharP(B), (L)))
#define SANITIZE_MEM(B,L) likely (
context->check (sanitize_depth
, CharP(B), (L)))
#define SANITIZE_ARRAY(A,S,L) likely (
_hb_sanitize_array (SANITIZE_ARG
, CharP(A), S, L))
#define SANITIZE_ARRAY(A,S,L) likely (
context->check_array (sanitize_depth
, CharP(A), S, L))
/* Template to sanitize an object. */
...
...
@@ -253,31 +259,31 @@ struct Sanitizer
if
(
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"Sanitizer %p start %s
\n
"
,
blob
,
HB_FUNC
);
_hb_sanitize_init
(
context
,
blob
);
context
->
init
(
blob
);
Type
*
t
=
CastP
<
Type
>
(
const_cast
<
char
*>
(
context
->
start
));
Type
*
t
=
CastP
<
Type
>
(
const_cast
<
char
*>
(
context
->
get_start
()
));
sane
=
t
->
sanitize
(
SANITIZE_ARG
);
if
(
sane
)
{
if
(
context
->
edit_count
)
{
if
(
context
->
get_edit_count
()
)
{
if
(
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"Sanitizer %p passed first round with %d edits; doing a second round %s
\n
"
,
blob
,
context
->
edit_count
,
HB_FUNC
);
blob
,
context
->
get_edit_count
()
,
HB_FUNC
);
/* sanitize again to ensure no toe-stepping */
context
->
edit_count
=
0
;
context
->
reset_edit_count
()
;
sane
=
t
->
sanitize
(
SANITIZE_ARG
);
if
(
context
->
edit_count
)
{
if
(
context
->
get_edit_count
()
)
{
if
(
HB_DEBUG_SANITIZE
)
fprintf
(
stderr
,
"Sanitizer %p requested %d edits in second round; FAILLING %s
\n
"
,
blob
,
context
->
edit_count
,
HB_FUNC
);
blob
,
context
->
get_edit_count
()
,
HB_FUNC
);
sane
=
false
;
}
}
_hb_sanitize_fini
(
context
,
blob
);
context
->
finish
(
);
}
else
{
unsigned
int
edit_count
=
context
->
edit_count
;
_hb_sanitize_fini
(
context
,
blob
);
unsigned
int
edit_count
=
context
->
get_edit_count
()
;
context
->
finish
(
);
if
(
edit_count
&&
!
hb_blob_is_writable
(
blob
)
&&
hb_blob_try_writable
(
blob
))
{
/* ok, we made it writable by relocating. try again */
if
(
HB_DEBUG_SANITIZE
)
...
...
@@ -465,7 +471,7 @@ struct GenericOffsetTo : OffsetType
private:
/* Set the offset to Null */
inline
bool
neuter
(
SANITIZE_ARG_DEF
)
{
if
(
_hb_sanitize_edit
(
SANITIZE_ARG
,
CharP
(
this
),
this
->
get_size
()))
{
if
(
context
->
can_edit
(
sanitize_depth
,
CharP
(
this
),
this
->
get_size
()))
{
this
->
set
(
0
);
/* 0 is Null offset */
return
true
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录