Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
abcc2354
Commit
abcc2354
authored
Nov 15, 2012
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bmp: return meaningful error codes.
parent
6a97ea65
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
15 deletions
+15
-15
bmp.c
libavcodec/bmp.c
+15
-15
No files found.
libavcodec/bmp.c
View file @
abcc2354
...
@@ -49,7 +49,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
...
@@ -49,7 +49,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
unsigned
int
depth
;
unsigned
int
depth
;
BiCompression
comp
;
BiCompression
comp
;
unsigned
int
ihsize
;
unsigned
int
ihsize
;
int
i
,
j
,
n
,
linesize
;
int
i
,
j
,
n
,
linesize
,
ret
;
uint32_t
rgb
[
3
];
uint32_t
rgb
[
3
];
uint8_t
*
ptr
;
uint8_t
*
ptr
;
int
dsize
;
int
dsize
;
...
@@ -58,13 +58,13 @@ static int bmp_decode_frame(AVCodecContext *avctx,
...
@@ -58,13 +58,13 @@ static int bmp_decode_frame(AVCodecContext *avctx,
if
(
buf_size
<
14
)
{
if
(
buf_size
<
14
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"buf size too small (%d)
\n
"
,
buf_size
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"buf size too small (%d)
\n
"
,
buf_size
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
if
(
bytestream_get_byte
(
&
buf
)
!=
'B'
||
if
(
bytestream_get_byte
(
&
buf
)
!=
'B'
||
bytestream_get_byte
(
&
buf
)
!=
'M'
)
{
bytestream_get_byte
(
&
buf
)
!=
'M'
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"bad magic number
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"bad magic number
\n
"
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
fsize
=
bytestream_get_le32
(
&
buf
);
fsize
=
bytestream_get_le32
(
&
buf
);
...
@@ -81,7 +81,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
...
@@ -81,7 +81,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
ihsize
=
bytestream_get_le32
(
&
buf
);
/* more header size */
ihsize
=
bytestream_get_le32
(
&
buf
);
/* more header size */
if
(
ihsize
+
14
>
hsize
)
{
if
(
ihsize
+
14
>
hsize
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid header size %d
\n
"
,
hsize
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid header size %d
\n
"
,
hsize
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
/* sometimes file size is set to some headers size, set a real size in that case */
/* sometimes file size is set to some headers size, set a real size in that case */
...
@@ -91,7 +91,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
...
@@ -91,7 +91,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
if
(
fsize
<=
hsize
)
{
if
(
fsize
<=
hsize
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"declared file size is less than header size (%d < %d)
\n
"
,
av_log
(
avctx
,
AV_LOG_ERROR
,
"declared file size is less than header size (%d < %d)
\n
"
,
fsize
,
hsize
);
fsize
,
hsize
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
switch
(
ihsize
)
{
switch
(
ihsize
)
{
...
@@ -108,13 +108,13 @@ static int bmp_decode_frame(AVCodecContext *avctx,
...
@@ -108,13 +108,13 @@ static int bmp_decode_frame(AVCodecContext *avctx,
break
;
break
;
default:
default:
av_log
(
avctx
,
AV_LOG_ERROR
,
"unsupported BMP file, patch welcome
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"unsupported BMP file, patch welcome
\n
"
);
return
-
1
;
return
AVERROR_PATCHWELCOME
;
}
}
/* planes */
/* planes */
if
(
bytestream_get_le16
(
&
buf
)
!=
1
)
{
if
(
bytestream_get_le16
(
&
buf
)
!=
1
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid BMP header
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid BMP header
\n
"
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
depth
=
bytestream_get_le16
(
&
buf
);
depth
=
bytestream_get_le16
(
&
buf
);
...
@@ -127,7 +127,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
...
@@ -127,7 +127,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
if
(
comp
!=
BMP_RGB
&&
comp
!=
BMP_BITFIELDS
&&
comp
!=
BMP_RLE4
&&
if
(
comp
!=
BMP_RGB
&&
comp
!=
BMP_BITFIELDS
&&
comp
!=
BMP_RLE4
&&
comp
!=
BMP_RLE8
)
{
comp
!=
BMP_RLE8
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"BMP coding %d not supported
\n
"
,
comp
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"BMP coding %d not supported
\n
"
,
comp
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
if
(
comp
==
BMP_BITFIELDS
)
{
if
(
comp
==
BMP_BITFIELDS
)
{
...
@@ -192,26 +192,26 @@ static int bmp_decode_frame(AVCodecContext *avctx,
...
@@ -192,26 +192,26 @@ static int bmp_decode_frame(AVCodecContext *avctx,
avctx
->
pix_fmt
=
AV_PIX_FMT_PAL8
;
avctx
->
pix_fmt
=
AV_PIX_FMT_PAL8
;
}
else
{
}
else
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Unknown palette for %d-colour BMP
\n
"
,
1
<<
depth
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"Unknown palette for %d-colour BMP
\n
"
,
1
<<
depth
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
break
;
break
;
default:
default:
av_log
(
avctx
,
AV_LOG_ERROR
,
"depth %d not supported
\n
"
,
depth
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"depth %d not supported
\n
"
,
depth
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
if
(
avctx
->
pix_fmt
==
AV_PIX_FMT_NONE
)
{
if
(
avctx
->
pix_fmt
==
AV_PIX_FMT_NONE
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"unsupported pixel format
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"unsupported pixel format
\n
"
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
if
(
p
->
data
[
0
])
if
(
p
->
data
[
0
])
avctx
->
release_buffer
(
avctx
,
p
);
avctx
->
release_buffer
(
avctx
,
p
);
p
->
reference
=
0
;
p
->
reference
=
0
;
if
(
ff_get_buffer
(
avctx
,
p
)
<
0
)
{
if
(
(
ret
=
ff_get_buffer
(
avctx
,
p
)
)
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"get_buffer() failed
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"get_buffer() failed
\n
"
);
return
-
1
;
return
ret
;
}
}
p
->
pict_type
=
AV_PICTURE_TYPE_I
;
p
->
pict_type
=
AV_PICTURE_TYPE_I
;
p
->
key_frame
=
1
;
p
->
key_frame
=
1
;
...
@@ -225,7 +225,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
...
@@ -225,7 +225,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
if
(
n
*
avctx
->
height
>
dsize
&&
comp
!=
BMP_RLE4
&&
comp
!=
BMP_RLE8
)
{
if
(
n
*
avctx
->
height
>
dsize
&&
comp
!=
BMP_RLE4
&&
comp
!=
BMP_RLE8
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"not enough data (%d < %d)
\n
"
,
av_log
(
avctx
,
AV_LOG_ERROR
,
"not enough data (%d < %d)
\n
"
,
dsize
,
n
*
avctx
->
height
);
dsize
,
n
*
avctx
->
height
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
// RLE may skip decoding some picture areas, so blank picture before decoding
// RLE may skip decoding some picture areas, so blank picture before decoding
...
@@ -346,7 +346,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
...
@@ -346,7 +346,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
break
;
break
;
default:
default:
av_log
(
avctx
,
AV_LOG_ERROR
,
"BMP decoder is broken
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"BMP decoder is broken
\n
"
);
return
-
1
;
return
AVERROR_INVALIDDATA
;
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment