Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
a2a9a01e
Commit
a2a9a01e
authored
6 years ago
by
Maksim Shabunin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AVI container: verbose error messages
parent
6c4f618d
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
11 deletions
+14
-11
container_avi.cpp
modules/videoio/src/container_avi.cpp
+14
-11
No files found.
modules/videoio/src/container_avi.cpp
View file @
a2a9a01e
...
...
@@ -12,7 +12,7 @@ namespace cv
// Utility function for safe integer conversions
template
<
typename
D
,
typename
S
>
inline
D
safe_int_cast
(
S
val
)
inline
D
safe_int_cast
(
S
val
,
const
char
*
msg
=
0
)
{
typedef
std
::
numeric_limits
<
S
>
st
;
typedef
std
::
numeric_limits
<
D
>
dt
;
...
...
@@ -21,7 +21,10 @@ inline D safe_int_cast(S val)
const
bool
in_range_l
=
(
double
)
val
>=
(
double
)
dt
::
min
();
if
(
!
in_range_r
||
!
in_range_l
)
{
CV_Error_
(
cv
::
Error
::
StsOutOfRange
,
(
"Can not convert integer values (%s -> %s), value 0x%llx is out of range"
,
typeid
(
S
).
name
(),
typeid
(
D
).
name
(),
val
));
if
(
!
msg
)
CV_Error_
(
Error
::
StsOutOfRange
,
(
"Can not convert integer values (%s -> %s), value 0x%llx is out of range"
,
typeid
(
S
).
name
(),
typeid
(
D
).
name
(),
val
));
else
CV_Error
(
Error
::
StsOutOfRange
,
msg
);
}
return
static_cast
<
D
>
(
val
);
}
...
...
@@ -128,7 +131,7 @@ public:
VideoInputStream
();
VideoInputStream
(
const
String
&
filename
);
~
VideoInputStream
();
VideoInputStream
&
read
(
char
*
,
uint
64
_t
);
VideoInputStream
&
read
(
char
*
,
uint
32
_t
);
VideoInputStream
&
seekg
(
uint64_t
);
uint64_t
tellg
();
bool
isOpened
()
const
;
...
...
@@ -229,11 +232,11 @@ void VideoInputStream::close()
}
}
VideoInputStream
&
VideoInputStream
::
read
(
char
*
buf
,
uint
64
_t
count
)
VideoInputStream
&
VideoInputStream
::
read
(
char
*
buf
,
uint
32
_t
count
)
{
if
(
isOpened
())
{
input
.
read
(
buf
,
safe_int_cast
<
std
::
streamsize
>
(
count
));
input
.
read
(
buf
,
safe_int_cast
<
std
::
streamsize
>
(
count
,
"Failed to read AVI file: requested chunk size is too large"
));
m_is_valid
=
(
input
.
gcount
()
==
(
std
::
streamsize
)
count
);
}
...
...
@@ -243,7 +246,7 @@ VideoInputStream& VideoInputStream::read(char* buf, uint64_t count)
VideoInputStream
&
VideoInputStream
::
seekg
(
uint64_t
pos
)
{
input
.
clear
();
input
.
seekg
(
safe_int_cast
<
std
::
streamoff
>
(
pos
));
input
.
seekg
(
safe_int_cast
<
std
::
streamoff
>
(
pos
,
"Failed to seek in AVI file: position is out of range"
));
m_is_valid
=
!
input
.
eof
();
return
*
this
;
}
...
...
@@ -668,7 +671,7 @@ void BitStream::writeBlock()
}
size_t
BitStream
::
getPos
()
const
{
return
safe_int_cast
<
size_t
>
(
m_current
-
m_start
)
+
m_pos
;
return
safe_int_cast
<
size_t
>
(
m_current
-
m_start
,
"Failed to determine AVI bufer position: value is out of range"
)
+
m_pos
;
}
void
BitStream
::
putByte
(
int
val
)
...
...
@@ -737,7 +740,7 @@ void BitStream::patchInt(uint32_t val, size_t pos)
{
if
(
pos
>=
m_pos
)
{
ptrdiff_t
delta
=
safe_int_cast
<
ptrdiff_t
>
(
pos
-
m_pos
);
ptrdiff_t
delta
=
safe_int_cast
<
ptrdiff_t
>
(
pos
-
m_pos
,
"Failed to seek in AVI buffer: value is out of range"
);
CV_Assert
(
delta
<
m_current
-
m_start
);
m_start
[
delta
]
=
(
uchar
)
val
;
m_start
[
delta
+
1
]
=
(
uchar
)(
val
>>
8
);
...
...
@@ -747,7 +750,7 @@ void BitStream::patchInt(uint32_t val, size_t pos)
else
{
std
::
streamoff
fpos
=
output
.
tellp
();
output
.
seekp
(
safe_int_cast
<
std
::
streamoff
>
(
pos
));
output
.
seekp
(
safe_int_cast
<
std
::
streamoff
>
(
pos
,
"Failed to seek in AVI file: value is out of range"
));
uchar
buf
[]
=
{
(
uchar
)
val
,
(
uchar
)(
val
>>
8
),
(
uchar
)(
val
>>
16
),
(
uchar
)(
val
>>
24
)
};
output
.
write
((
char
*
)
buf
,
4
);
output
.
seekp
(
fpos
);
...
...
@@ -960,7 +963,7 @@ void AVIWriteContainer::endWriteChunk()
size_t
pospos
=
AVIChunkSizeIndex
.
back
();
AVIChunkSizeIndex
.
pop_back
();
CV_Assert
(
currpos
>=
pospos
);
uint32_t
chunksz
=
safe_int_cast
<
uint32_t
>
(
currpos
-
pospos
);
uint32_t
chunksz
=
safe_int_cast
<
uint32_t
>
(
currpos
-
pospos
,
"Failed to write AVI file: chunk size is out of bounds"
);
strm
->
patchInt
(
chunksz
,
pospos
);
}
}
...
...
@@ -996,7 +999,7 @@ void AVIWriteContainer::writeIndex(int stream_number, StreamType strm_type)
void
AVIWriteContainer
::
finishWriteAVI
()
{
uint32_t
nframes
=
safe_int_cast
<
uint32_t
>
(
frameOffset
.
size
());
uint32_t
nframes
=
safe_int_cast
<
uint32_t
>
(
frameOffset
.
size
()
,
"Failed to write AVI file: number of frames is too large"
);
// Record frames numbers to AVI Header
while
(
!
frameNumIndexes
.
empty
())
{
...
...
This diff is collapsed.
Click to expand it.
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