Skip to content

Commit f474dcc

Browse files
committed
Check correctness of the data read operation
1 parent bb141c5 commit f474dcc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ario/ario.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,17 @@ class ario
9494
std::string data( size, '\0' );
9595
std::streamoff current_pos = pstream->tellg();
9696
pstream->seekg( filepos + HEADER_SIZE, std::ios::beg );
97+
if ( pstream->fail() ) {
98+
return { "Failed to seek to member data position" };
99+
}
97100
pstream->read( &data[0], size );
101+
if ( pstream->fail() || (size_t)pstream->gcount() < size ) {
102+
return { "Failed to read member data" };
103+
}
104+
105+
// Reset the stream position
98106
pstream->clear();
99107
pstream->seekg( current_pos, std::ios::beg );
100-
if ( (size_t)pstream->gcount() < size ) {
101-
return { "Member data read error" };
102-
}
103108

104109
return data;
105110
}

0 commit comments

Comments
 (0)