Skip to content

Commit bad7131

Browse files
Merge pull request #96 from DataDog/rgs/constant-pool-overflow
check space before writing long strings into constant pool
2 parents 2c0e7dd + 6f05d42 commit bad7131

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/flightRecorder.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const int MAX_STRING_LENGTH = 8191;
5050
const u64 MAX_JLONG = 0x7fffffffffffffffULL;
5151
const u64 MIN_JLONG = 0x8000000000000000ULL;
5252
const int MAX_JFR_EVENT_SIZE = 256;
53-
const int JFR_EVENT_FLUSH_THRESHOLD = RECORDING_BUFFER_LIMIT - MAX_JFR_EVENT_SIZE;
53+
const int JFR_EVENT_FLUSH_THRESHOLD = RECORDING_BUFFER_LIMIT;
5454

5555

5656
static SpinLock _rec_lock(1);
@@ -1168,9 +1168,11 @@ class Recording {
11681168
buf->putVar64(type);
11691169
buf->putVar64(constants.size());
11701170
for (std::map<u32, const char*>::const_iterator it = constants.begin(); it != constants.end(); ++it) {
1171+
int length = strlen(it->second);
1172+
// 5 is max varint length
1173+
flushIfNeeded(buf, RECORDING_BUFFER_LIMIT - length - 5);
11711174
buf->putVar64(it->first | _base_id);
1172-
buf->putUtf8(it->second);
1173-
flushIfNeeded(buf);
1175+
buf->putUtf8(it->second, length);
11741176
}
11751177
}
11761178

0 commit comments

Comments
 (0)