code in question
private ComponentType* CalculateRequiredComponentsFromQuery(ref UnsafeScratchAllocator allocator, ArchetypeQuery* queries, int queryCount, out int outRequiredComponentsCount)
{
var maxIntersectionCount = 0;
for (int queryIndex = 0; queryIndex < queryCount; ++queryIndex)
maxIntersectionCount = math.max(maxIntersectionCount, queries[queryIndex].AllCount + queries[queryIndex].DisabledCount);
var outRequiredComponents = (ComponentType*)allocator.Allocate<ComponentType>(maxIntersectionCount+1);
outRequiredComponents[0] = ComponentType.ReadWrite<Entity>();
var intersection = outRequiredComponents + 1;
for (int j = 0; j < queries[0].AllCount; ++j)
{
intersection[j] = new ComponentType
{
TypeIndex = queries[0].All[j],
AccessModeType = (ComponentType.AccessMode)queries[0].AllAccessMode[j],
};
}
for (int j = 0; j < queries[0].DisabledCount; ++j)
{
intersection[j+queries[0].AllCount] = new ComponentType
{
TypeIndex = queries[0].Disabled[j],
AccessModeType = (ComponentType.AccessMode)queries[0].DisabledAccessMode[j],
};
}
NativeSortExtension.Sort(intersection, maxIntersectionCount);
Only the size of queries[0].AllCount + queries[0].DisabledCount is being written to intersection therefore if maxIntersectionCount is greater than this there is a very very very small chance the memory at the location would match a component