FFL-1450 fix memory corruption in flag_metadata#1368
Conversation
BenchmarksComparisonBenchmark execution time: 2025-11-24 21:01:13 Comparing candidate commit 067fd56 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 55 metrics, 2 unstable metrics. CandidateCandidate benchmark detailsGroup 1
Group 2
Group 3
Group 4
Group 5
Group 6
Group 7
Group 8
Group 9
Group 10
Group 11
Group 12
Group 13
Group 14
Group 15
Group 16
Group 17
BaselineOmitted due to size. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1368 +/- ##
=======================================
Coverage 71.19% 71.20%
=======================================
Files 392 392
Lines 62677 62751 +74
=======================================
+ Hits 44626 44684 +58
- Misses 18051 18067 +16
🚀 New features to boost your workflow:
|
Artifact Size Benchmark Reportaarch64-alpine-linux-musl
aarch64-apple-darwin
aarch64-unknown-linux-gnu
libdatadog-x64-windows
libdatadog-x86-windows
x86_64-alpine-linux-musl
x86_64-apple-darwin
x86_64-unknown-linux-gnu
|
| .map(|(k, v)| { | ||
| KeyValue { | ||
| // SAFETY: the borrow is valid as long as string allocation is | ||
| // alive. ResolutionDetails will get moved into heap but this does not |
There was a problem hiding this comment.
Ok I think I understand. ResolutionDetails moves, and since Assignment is owned directly by the struct due to inner: Result<Assignment, EvaluationError>, Assignment moves too. So,
let details = ResolutionDetails::new(Ok(value)); // details created
// BorrowedStr pointers in details are valid
let moved_details = details; // move happens
// now BorrowedStr pointers in moved_details are invalid
Thanks for updating the comments! They're helpful
There was a problem hiding this comment.
For a bit more context, this only affects a.allocation_key and does not affect extra_logging. This is because extra_logging strings are already stored in a Vec, which moves them to the heap. So when Vec moves, it does not move its content—it stays in the same place on the heap. This is also true for String, which stores content on the heap.
The issue occurs only with Str which has small string optimization and stores short strings (<= 24 bytes) inline in the structure and only because allocation_key is stored in Assignment directly without any heap-allocation container (e.g. Vec or HashMap)
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
What does this PR do?
Fix a memory corruption bug in flag_metadata.
Additional Notes
Strtype has small string optimization, whereas short strings are stored directly in the structure bytes instead of on heap. This means that taking a reference to anallocation_keystring was pointing to an str structure which was stored on stack at that time and was moved out when result was returned from the structure. When trying to printflag_metadata.allocationKey, it was printing garbage bytes from stack.This PR stores result on heap first (
Box) and pins it for extra measure, to make sure it's not moved. This allows us to create stable pointers toallocation_key.How to test the change?
Example was expanded to print flag metadata, so verified that it was corrupted before / fixed after the change.