diff --git a/.changeset/lazy-lamps-repair.md b/.changeset/lazy-lamps-repair.md new file mode 100644 index 00000000000..9445dacc3a5 --- /dev/null +++ b/.changeset/lazy-lamps-repair.md @@ -0,0 +1,5 @@ +--- +"fast-check": patch +--- + +🐛 Make depth retrieval more resilient to poisoning diff --git a/packages/fast-check/src/arbitrary/_internals/helpers/DepthContext.ts b/packages/fast-check/src/arbitrary/_internals/helpers/DepthContext.ts index 75ecc95b265..842a48cf093 100644 --- a/packages/fast-check/src/arbitrary/_internals/helpers/DepthContext.ts +++ b/packages/fast-check/src/arbitrary/_internals/helpers/DepthContext.ts @@ -1,3 +1,5 @@ +import { safeMapGet, safeMapSet } from '../../../utils/globals'; + /** * Internal symbol used to declare an opaque type for DepthIdentifier * @internal @@ -54,12 +56,12 @@ export function getDepthContextFor(contextMeta: DepthContext | DepthIdentifier | if (typeof contextMeta !== 'string') { return contextMeta as DepthContext; } - const cachedContext = depthContextCache.get(contextMeta); + const cachedContext = safeMapGet(depthContextCache, contextMeta); if (cachedContext !== undefined) { return cachedContext; } const context = { depth: 0 }; - depthContextCache.set(contextMeta, context); + safeMapSet(depthContextCache, contextMeta, context); return context; }