Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/gha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
strategy:
fail-fast: false
matrix:
pattern: [0, 1, 2, 3, 4, 5, 6, 7, 8]
pattern: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
steps:
- uses: actions/checkout@v1
- name: install build depends
Expand Down Expand Up @@ -148,6 +148,16 @@ jobs:
ACTION="ci/build_cmake_embedded.sh"
export ARCH="64"
fi
if [ ${{ matrix.pattern }} == 9 ]; then
export CC=gcc
export CXX=g++
ACTION="ci/build_cmake.sh"
export ARCH="64"
export SHARED="ON"
export SAN="-fsanitize=address -fno-omit-frame-pointer"
export CHAR_SIGN="signed"
LIMITS="-DMSGPACK_UNPACK_ARRAY_LIMIT=100000 -DMSGPACK_UNPACK_MAP_LIMIT=100000"
fi

# install gtest
wget https://github.com/google/googletest/archive/v1.13.0.zip -O googletest-1.13.0.zip
Expand All @@ -164,7 +174,7 @@ jobs:
fi

# build and test
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" GTEST_ROOT="${BASE}/usr" CFLAGS="-Werror -g -gdwarf-4 -fsanitize=undefined -fno-sanitize-recover=all" CXXFLAGS="-Werror -g -ggdb3 -gdwarf-4 -fsanitize=undefined -fno-sanitize-recover=all" ${ACTION}
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" GTEST_ROOT="${BASE}/usr" CFLAGS="-Werror -g -gdwarf-4 -fsanitize=undefined -fno-sanitize-recover=all ${LIMITS}" CXXFLAGS="-Werror -g -ggdb3 -gdwarf-4 -fsanitize=undefined -fno-sanitize-recover=all" ${ACTION}

windows:
runs-on: windows-2022
Expand Down
32 changes: 32 additions & 0 deletions src/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,28 @@ static inline int template_callback_false(unpack_user* u, msgpack_object* o)
return 0;
}

/*
* Optional, compile-time hardening limits for the number of elements an
* array, or key/value pairs a map, may declare before its backing store is
* allocated. They bound the up-front allocation that a tiny message can
* request: a 5-byte array32/map32 header (e.g. 0xdf 0xff 0xff 0xff 0xff) can
* otherwise ask for ~100-200 GB before a single element byte is read, which
* makes a resource-exhaustion attack very cheap (see issue #1013).
*
* Both default to 0, which means "no limit" and preserves the previous
* behavior exactly: with the default the checks below compile out entirely.
* Define them to a non-zero value at build time
* (e.g. -DMSGPACK_UNPACK_ARRAY_LIMIT=1000000) to reject any array or map
* whose declared element count exceeds the limit with
* MSGPACK_UNPACK_PARSE_ERROR.
*/
#ifndef MSGPACK_UNPACK_ARRAY_LIMIT
#define MSGPACK_UNPACK_ARRAY_LIMIT 0
#endif
#ifndef MSGPACK_UNPACK_MAP_LIMIT
#define MSGPACK_UNPACK_MAP_LIMIT 0
#endif

static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_object* o)
{
size_t size;
Expand All @@ -199,6 +221,11 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac
return MSGPACK_UNPACK_NOMEM_ERROR;
#endif

#if MSGPACK_UNPACK_ARRAY_LIMIT
if (n > MSGPACK_UNPACK_ARRAY_LIMIT)
return MSGPACK_UNPACK_PARSE_ERROR;
#endif

o->type = MSGPACK_OBJECT_ARRAY;
o->via.array.size = 0;

Expand Down Expand Up @@ -243,6 +270,11 @@ static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_
return MSGPACK_UNPACK_NOMEM_ERROR;
#endif

#if MSGPACK_UNPACK_MAP_LIMIT
if (n > MSGPACK_UNPACK_MAP_LIMIT)
return MSGPACK_UNPACK_PARSE_ERROR;
#endif

o->type = MSGPACK_OBJECT_MAP;
o->via.map.size = 0;

Expand Down
Loading