Skip to content

Commit 90ff17b

Browse files
fix(profiling): integrate Stack Chunk size fix
1 parent f8331f2 commit 90ff17b

File tree

1 file changed

+9
-0
lines changed
  • ddtrace/internal/datadog/profiling/stack_v2/echion/echion

1 file changed

+9
-0
lines changed

ddtrace/internal/datadog/profiling/stack_v2/echion/echion/stack_chunk.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <echion/errors.h>
1919
#include <echion/vm.h>
2020

21+
const constexpr size_t MAX_CHUNK_SIZE = 256 * 1024; // 256KB
22+
2123
// ----------------------------------------------------------------------------
2224
class StackChunk
2325
{
@@ -45,6 +47,13 @@ StackChunk::update(_PyStackChunk* chunk_addr)
4547
return ErrorKind::StackChunkError;
4648
}
4749

50+
// It's possible that the memory we read is corrupted/not valid anymore and the
51+
// chunk.size is not meaningful. Weed out those cases here to make sure we don't
52+
// try to allocate absurd amounts of memory.
53+
if (chunk.size > MAX_CHUNK_SIZE) {
54+
return ErrorKind::StackChunkError;
55+
}
56+
4857
origin = chunk_addr;
4958
// if data_capacity is not enough, reallocate.
5059
if (chunk.size > data_capacity) {

0 commit comments

Comments
 (0)