RFR: 8320222: Wrong bytecode accepted, and StackMap table generated

Chen Liang liach at openjdk.org
Thu Nov 16 11:28:30 UTC 2023


On Thu, 16 Nov 2023 10:00:44 GMT, Adam Sotona <asotona at openjdk.org> wrote:

> Stack map generator in ClassFile API performs only minimal checks in favour of performance.
> However it led to situations where it generates invalid stack maps for corrupted code.
> This patch adds basic checks of stack when two frames are merged and throws an exception in case of stack size or content mismatch. Generated or transformed code with inconsistent stack will fail on stack maps generation.
> Relevant tests are added.
> 
> Please review.
> 
> Thanks,
> Adam

src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java line 1138:

> 1136:                 }
> 1137:                 if (stackSize != target.stackSize) {
> 1138:                     generatorError("Stack size mismatch");

Just a side comment, `generatorError` should return a Throwable than throw directly, so when used as `throw generatorError()`, it is more clear that the code branch will terminate to javac.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16685#discussion_r1395551761


More information about the core-libs-dev mailing list