Skip to content

Commit 954d202

Browse files
committed
Merge commit '214b508d41fe45a9b3b0b71d55bffe02ad49452d'
2 parents fcbdf9c + 214b508 commit 954d202

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/foldseek/src/strucclustutils/structcreatedb.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,10 @@ int structcreatedb(int argc, const char **argv, const Command& command) {
927927
if (tar.isFinished == 0 && (mtar_read_header(&tar, &tarHeader)) != MTAR_ENULLRECORD) {
928928
// GNU tar has special blocks for long filenames
929929
if (tarHeader.type == MTAR_TGNU_LONGNAME || tarHeader.type == MTAR_TGNU_LONGLINK) {
930+
if (tarHeader.size == 0) {
931+
Debug(Debug::ERROR) << "Invalid tar input with long name/link record of size 0\n";
932+
EXIT(EXIT_FAILURE);
933+
}
930934
if (tarHeader.size > bufferSize) {
931935
bufferSize = tarHeader.size * 1.5;
932936
dataBuffer = (char *) realloc(dataBuffer, bufferSize);
@@ -935,7 +939,8 @@ int structcreatedb(int argc, const char **argv, const Command& command) {
935939
Debug(Debug::ERROR) << "Cannot read entry " << tarHeader.name << "\n";
936940
EXIT(EXIT_FAILURE);
937941
}
938-
name.assign(dataBuffer, tarHeader.size);
942+
// skip null byte
943+
name.assign(dataBuffer, tarHeader.size - 1);
939944
// skip to next record
940945
if (mtar_read_header(&tar, &tarHeader) == MTAR_ENULLRECORD) {
941946
Debug(Debug::ERROR) << "Tar truncated after entry " << name << "\n";

0 commit comments

Comments
 (0)