AE2 Unofficial Extended Life

AE2 Unofficial Extended Life

3M Downloads

Hash collisions of item stacks causing wrong items to be stored

kurrycat2004 opened this issue · 8 comments

commented

Describe the bug

AEItemStackRegistry#getRegisteredStack(ItemStack) only compares the hash of the input stack, without comparing the actual item stacks, making it vulnerable to hash collisions. This causes new items put into a system to "transform" into the already existing item if it has the same hash.

To Reproduce

  • make a simple ME system
  • put a Protection 1 enchanted book in
  • put a Fire Protection 2 enchanted book in
  • system now contains 2 Protection 1 books

Expected behavior

ME System correctly stores one Protection 1 book and one Fire Protection 2 book

Additional context

javaw_JnTSTzqIUE.mp4

Environment

Tested with only AE2

  • Minecraft Version: 1.12.2
  • AE2 Version: v0.56.6
  • Forge Version: 14.23.5.2847
commented

Is this an issue in original AE?

commented

from what i could see, no

commented

For what it's worth, 0.56.6 has known issues and I was advised months ago not to update to it because of that.

commented

This appears to be a regression from 0.56.6; downgrading to 0.56.5 fixes it. Most likely this commit: 724f3ba

commented

Yes, that should also check identity equals. AE2 seems to use this: 724f3ba, a 'Weak Values' Map from Google. Not sure if it is what I thought.

commented

this is concerning for CEu, since it uses the same kind of hash strategy

commented

CEu uses this in OpenCustomHashMaps (from fastutil), i'm not sure if those use both hash and identity equals.

commented

If CEu does, wouldn't it use a normal map, and not a weak map? From what I see in 724f3ba, I believe AE2 is using a weak map, which... doesn't compare equality, just hash, right?

At least, that is what I believe is happening, as normal maps check both hash and the equals function.