Coder Social home page Coder Social logo

binaryoffheaphashmap's People

Contributors

cfelde avatar vkazanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

binaryoffheaphashmap's Issues

Error while iteration on map values after removal

Hi,
I experienced strange behaviour of OHMap after removal of element. Here is sample code to generate issue:

    String KEY = "KEY";
    String VALUE = "VALUE";
    OHMap<String, String> ohMap = new OHMap<>(10);
    ohMap.put(KEY, VALUE);
    ohMap.remove(KEY);
    Iterator<String> iterator = ohMap.values().iterator();
    if (iterator.hasNext()) {
        iterator.next();
    }

It generates JVM crash:

# 
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f2a1f9c9aed, pid=25433, tid=0x00007f2a1e608700
#
# JRE version: OpenJDK Runtime Environment (8.0_242-b08) (build 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08)
# Java VM: OpenJDK 64-Bit Server VM (25.242-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0xa81aed]

or Exception:

java.lang.NegativeArraySizeException
	at com.cfelde.bohmap.BOHMap$ValuesIterator.next(BOHMap.java:1009)
	at com.cfelde.bohmap.BOHMap$ValuesIterator.next(BOHMap.java:944)
	at com.cfelde.bohmap.OHMap$Values$1.next(OHMap.java:282)
	at com.cfelde.bohmap.OHMap$Values$1.next(OHMap.java:274)

It looks like iterator#hasNext return true, but Iterator#next causes exception/crash.

BOHMap can crash JVM

BOHMap calculates offset into the partition using the following code:

 final int hash = Math.abs(hashFunction.apply(keyData));
 final long offset = hash % partitionCount;

If hashFunction returns Integer.MIN_VALUE (i.e. -2147483648) Math.abs will return a negative number. A native offset into a buffer most of the time will crash the process, if not worse.

Check out, for example, this explanation.

This can be easily fixed by doing something like this instead:

final long offset = Math.abs(hashFunction.apply(keyData) % partitionCount);

I actually have a proper fix. Should I open a PR?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.