Search code examples
javabuffer-overflowbuffer-overrun

Does Java have buffer overflows?


Does Java have buffer overflows? If yes can you give me scenarios?


Solution

  • Since Java Strings are based on char arrays and Java automatically checks array bounds, buffer overflows are only possible in unusual scenarios:

    1. If you call native code via JNI
    2. In the JVM itself (usually written in C++)
    3. The interpreter or JIT compiler does not work correctly (Java bytecode mandated bounds checks)