Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8361906

Missing List length validation in the Class-File API

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • core-libs
    • None
    • behavioral
    • low
    • These are behavioral changes, but had those run successfully, the output is always malformed and not compliant `class` file format recognized by the JVMS.
    • Java API
    • SE

      Summary

      Add IllegalArgumentException behavior to methods that construct Class-File API models if oversized lists are passed.

      Problem

      The class file format has physical restriction for size of lists. Most of the lists use a u2, a 2-byte unsigned value in the range [0, 65535], to encode their sizes; in three occasions (list size in MethodParameters, outer list size in RuntimeVisibleParameterAnnotations and RuntimeInvisibleParameterAnnotations, and path size in type_path structure used by type-use annotations) the sizes are encoded as u1, 1-byte unsigned in [0, 255].

      However, there are no restriction on such sizes and the API does not currently perform any check upon writing; this leads to malformed class files, and in no case the mismatched size and list length is an intended behavior.

      Solution

      Make these APIs validate their arguments eagerly, so they throw IAE whenever they receive oversized lists. For those that cannot eagerly validate (such as due to accumulation in builders), extra checks will be done on writing/building to throw IAE, like the existing IAE for oversized constant pool.

      Specification

      See attachment for details.

      Since the change is too huge, in fact, these are the list/arrays that did not receive this update in the Class-File API:

      • Options to construct ClassFile context object
      • SwitchCase for constructing tableswitch/lookupswitch (there is no explicit size restriction)
      • Signature (they are plain strings)

            liach Chen Liang
            liach Chen Liang
            Adam Sotona
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: