Skip to content

_ariaChecked: out-of-bounds access when position >= dotElems.length #54

Description

@javier-godoy

In src/main/resources/META-INF/resources/frontend/paper-slider/l2t-paper-slider.js, _ariaChecked guards the loop with if (dotElems.length > 0) but then unconditionally accesses dotElems[this.position]:

_ariaChecked: function () {
  var dotElems = this.$.container.querySelectorAll('.slider__dot');
  if (dotElems.length > 0) {
    for (var i = 0; i < dotElems.length; i++) {
      dotElems[i].setAttribute("aria-checked", "false");
    };
    dotElems[this.position].setAttribute("aria-checked", "true");
  }
},

During a dom-repeat render race (the same condition addressed by #50 / commit 6893f6d), this.position can exceed dotElems.length - 1, causing dotElems[this.position] to be undefined and .setAttribute to throw TypeError: Cannot read properties of undefined.

This is the same class of bug as #50 but at a distinct code site that the loop-bound fix in 6893f6d did not reach.

Suggested fix: bound-check this.position before the access.

if (this.position < dotElems.length) {
  dotElems[this.position].setAttribute("aria-checked", "true");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions