Skip to content

Commit

Permalink
Merge pull request #166 from hoene/issue-163
Browse files Browse the repository at this point in the history
Issue 163 Heap overflow
  • Loading branch information
hoene authored Oct 3, 2021
2 parents 74c4268 + 890400e commit 8423749
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ if(BUILD_TESTS)
136
137
138
156)
156
163)
# issues with osx 96)
add_test(fail-issue-${ISSUE} ${PROJECT_SOURCE_DIR}/tests/notcrashed.sh
${PROJECT_SOURCE_DIR}/tests/fail-issue-${ISSUE})
Expand Down
17 changes: 10 additions & 7 deletions src/hdf/dataobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,17 @@ static int readOHDRHeaderMessageDataLayout(struct READER *reader,
store = ftell(reader->fhd);
if (fseek(reader->fhd, data_address, SEEK_SET) < 0)
return errno; // LCOV_EXCL_LINE
if (!data->data) {
if (data_size > 0x10000000)
return MYSOFA_INVALID_FORMAT;
data->data_len = data_size;
data->data = calloc(1, data_size);
if (!data->data)
return MYSOFA_NO_MEMORY; // LCOV_EXCL_LINE
if (data->data) {
free(data->data);
data->data = NULL;
}
if (data_size > 0x10000000)
return MYSOFA_INVALID_FORMAT;
data->data_len = data_size;
data->data = calloc(1, data_size);
if (!data->data)
return MYSOFA_NO_MEMORY; // LCOV_EXCL_LINE

err = fread(data->data, 1, data_size, reader->fhd);
if (err != data_size)
return MYSOFA_READ_ERROR; // LCOV_EXCL_LINE
Expand Down
Binary file added tests/fail-issue-163.sofa
Binary file not shown.
4 changes: 1 addition & 3 deletions tests/notcrashed.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/bin/sh

test -f "$1".sofa || exit 128
../build/src/mysofa2json "$1".sofa >/dev/null 2>/dev/null
ret=$?
if [ "$ret" -ge 128 ]; then
if [ "$ret" -ge 128 ]; then
echo mysofa2json crashed with $ret opening$1.sofa
exit $ret
fi
fi
echo good
exit 0
Expand Down

0 comments on commit 8423749

Please sign in to comment.