Tencent/tinker · critical · IndexOutOfBoundsException

instruction index %d out of bounds

Error message

instruction index %d out of bounds

What it means

IndexOutOfBoundsException from BuilderMutableMethodImplementation.newLabelForIndex(int): the given instruction index is negative or >= instructionList.size(). It guards label creation by index instead of by code address, and fires on the same class of malformed-offset problems as newLabelForAddress.

Source

Thrown at tinker-build/tinker-patch-lib/src/main/java/org/jf/dexlib2/builder/BuilderMutableMethodImplementation.java:632

                index++;
            } while (index < instructionList.size() && instructionList.get(index).codeAddress <= codeAddress);
            return index - 1;
        }
    }

    @Nonnull
    public Label newLabelForAddress(int codeAddress) {
        if (codeAddress < 0 || codeAddress > instructionList.get(instructionList.size() - 1).codeAddress) {
            throw new IndexOutOfBoundsException(String.format("codeAddress %d out of bounds", codeAddress));
        }
        MethodLocation referent = instructionList.get(mapCodeAddressToIndex(codeAddress));
        return referent.addNewLabel();
    }

    @Nonnull
    public Label newLabelForIndex(int instructionIndex) {
        if (instructionIndex < 0 || instructionIndex >= instructionList.size()) {
            throw new IndexOutOfBoundsException(String.format("instruction index %d out of bounds", instructionIndex));
        }
        MethodLocation referent = instructionList.get(instructionIndex);
        return referent.addNewLabel();
    }

    @Nonnull
    private Label newLabel(@Nonnull int[] codeAddressToIndex, int codeAddress) {
        MethodLocation referent = instructionList.get(mapCodeAddressToIndex(codeAddressToIndex, codeAddress));
        return referent.addNewLabel();
    }

    private static class SwitchPayloadReferenceLabel extends Label {
        @Nonnull
        public MethodLocation switchLocation;
    }

    @Nonnull
    public Label newSwitchPayloadReferenceLabel(@Nonnull MethodLocation switchLocation,

View on GitHub (pinned to 1b7ea02c23)

Solutions

  1. If calling the API directly, clamp/validate the index against the instruction list size first
  2. Upgrade Tinker/dexlib2 for newer dex compatibility
  3. Verify the input dex parses cleanly with standard tools (e.g., baksmali) before patching
Defensive patterns

Strategy: validation

Validate before calling

if (instructionIndex < 0 || instructionIndex >= instructions.size()) {
    throw new IllegalArgumentException("index out of range: " + instructionIndex);
}
impl.newLabelForIndex(instructionIndex);

Prevention

When it happens

Trigger: Calling newLabelForIndex with an index past the end of the method's instruction list, or dexlib2 internally computing such an index from a bogus offset during builder conversion.

Common situations: Malformed dex from obfuscators; tools passing raw indices into the builder without bounds checks; corrupted patch application.

Related errors


AI-assisted analysis of Tencent/tinker@1b7ea02c23 (2026-08-14). Data as JSON: /api/errors/8a79a8de13210203. Report an issue: GitHub.