Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
itdan3344
stb
提交
62f37275
S
stb
项目概览
itdan3344
/
stb
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
stb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
62f37275
编写于
8月 12, 2016
作者:
F
Fabian Giesen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stb_image: Fix HDR/PSD RLE decoders.
Runs need to be bounds checked. Fixes issues #315, #317.
上级
02190634
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
56 addition
and
33 deletion
+56
-33
stb_image.h
stb_image.h
+56
-33
未找到文件。
stb_image.h
浏览文件 @
62f37275
...
...
@@ -5392,11 +5392,49 @@ static int stbi__psd_test(stbi__context *s)
return
r
;
}
static
int
stbi__psd_decode_rle
(
stbi__context
*
s
,
stbi_uc
*
p
,
int
pixelCount
)
{
int
count
,
nleft
,
len
;
count
=
0
;
while
((
nleft
=
pixelCount
-
count
)
>
0
)
{
len
=
stbi__get8
(
s
);
if
(
len
==
128
)
{
// No-op.
}
else
if
(
len
<
128
)
{
// Copy next len+1 bytes literally.
len
++
;
if
(
len
>
nleft
)
return
0
;
// corrupt data
count
+=
len
;
while
(
len
)
{
*
p
=
stbi__get8
(
s
);
p
+=
4
;
len
--
;
}
}
else
if
(
len
>
128
)
{
stbi_uc
val
;
// Next -len+1 bytes in the dest are replicated from next source byte.
// (Interpret len as a negative 8-bit int.)
len
=
257
-
len
;
if
(
len
>
nleft
)
return
0
;
// corrupt data
val
=
stbi__get8
(
s
);
count
+=
len
;
while
(
len
)
{
*
p
=
val
;
p
+=
4
;
len
--
;
}
}
}
return
1
;
}
static
stbi_uc
*
stbi__psd_load
(
stbi__context
*
s
,
int
*
x
,
int
*
y
,
int
*
comp
,
int
req_comp
)
{
int
pixelCount
;
int
pixelCount
;
int
channelCount
,
compression
;
int
channel
,
i
,
count
,
len
;
int
channel
,
i
;
int
bitdepth
;
int
w
,
h
;
stbi_uc
*
out
;
...
...
@@ -5493,34 +5531,9 @@ static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int
*
p
=
(
channel
==
3
?
255
:
0
);
}
else
{
// Read the RLE data.
count
=
0
;
while
(
count
<
pixelCount
)
{
len
=
stbi__get8
(
s
);
if
(
len
==
128
)
{
// No-op.
}
else
if
(
len
<
128
)
{
// Copy next len+1 bytes literally.
len
++
;
count
+=
len
;
while
(
len
)
{
*
p
=
stbi__get8
(
s
);
p
+=
4
;
len
--
;
}
}
else
if
(
len
>
128
)
{
stbi_uc
val
;
// Next -len+1 bytes in the dest are replicated from next source byte.
// (Interpret len as a negative 8-bit int.)
len
^=
0x0FF
;
len
+=
2
;
val
=
stbi__get8
(
s
);
count
+=
len
;
while
(
len
)
{
*
p
=
val
;
p
+=
4
;
len
--
;
}
}
if
(
!
stbi__psd_decode_rle
(
s
,
p
,
pixelCount
))
{
STBI_FREE
(
out
);
return
stbi__errpuc
(
"corrupt"
,
"bad RLE data"
);
}
}
}
...
...
@@ -6325,20 +6338,29 @@ static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int re
len
<<=
8
;
len
|=
stbi__get8
(
s
);
if
(
len
!=
width
)
{
STBI_FREE
(
hdr_data
);
STBI_FREE
(
scanline
);
return
stbi__errpf
(
"invalid decoded scanline length"
,
"corrupt HDR"
);
}
if
(
scanline
==
NULL
)
scanline
=
(
stbi_uc
*
)
stbi__malloc
(
width
*
4
);
if
(
scanline
==
NULL
)
{
scanline
=
(
stbi_uc
*
)
stbi__malloc_mad2
(
width
,
4
,
0
);
if
(
!
scanline
)
{
STBI_FREE
(
hdr_data
);
return
stbi__errpf
(
"outofmem"
,
"Out of memory"
);
}
}
for
(
k
=
0
;
k
<
4
;
++
k
)
{
int
nleft
;
i
=
0
;
while
(
i
<
width
)
{
while
(
(
nleft
=
width
-
i
)
>
0
)
{
count
=
stbi__get8
(
s
);
if
(
count
>
128
)
{
// Run
value
=
stbi__get8
(
s
);
count
-=
128
;
if
(
count
>
nleft
)
{
STBI_FREE
(
hdr_data
);
STBI_FREE
(
scanline
);
return
stbi__errpf
(
"corrupt"
,
"bad RLE data in HDR"
);
}
for
(
z
=
0
;
z
<
count
;
++
z
)
scanline
[
i
++
*
4
+
k
]
=
value
;
}
else
{
// Dump
if
(
count
>
nleft
)
{
STBI_FREE
(
hdr_data
);
STBI_FREE
(
scanline
);
return
stbi__errpf
(
"corrupt"
,
"bad RLE data in HDR"
);
}
for
(
z
=
0
;
z
<
count
;
++
z
)
scanline
[
i
++
*
4
+
k
]
=
stbi__get8
(
s
);
}
...
...
@@ -6347,7 +6369,8 @@ static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int re
for
(
i
=
0
;
i
<
width
;
++
i
)
stbi__hdr_convert
(
hdr_data
+
(
j
*
width
+
i
)
*
req_comp
,
scanline
+
i
*
4
,
req_comp
);
}
STBI_FREE
(
scanline
);
if
(
scanline
)
STBI_FREE
(
scanline
);
}
return
hdr_data
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录