Skip to content

Commit

Permalink
Merge pull request mozilla#18890 from calixteman/clamp_indexedcs_hival
Browse files Browse the repository at this point in the history
Clamp the hival parameter of Indexed color space to the range [0; 255]
  • Loading branch information
calixteman authored Oct 12, 2024
2 parents e28dd8e + 4dea773 commit 1c0c070
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/core/colorspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ class ColorSpace {
case "I":
case "Indexed":
baseCS = this._parse(cs[1], xref, resources, pdfFunctionFactory);
const hiVal = xref.fetchIfRef(cs[2]) + 1;
const hiVal = Math.max(0, Math.min(xref.fetchIfRef(cs[2]), 255));
const lookup = xref.fetchIfRef(cs[3]);
return new IndexedCS(baseCS, hiVal, lookup);
case "Separation":
Expand Down Expand Up @@ -630,9 +630,8 @@ class IndexedCS extends ColorSpace {
constructor(base, highVal, lookup) {
super("Indexed", 1);
this.base = base;
this.highVal = highVal;

const length = base.numComps * highVal;
const length = base.numComps * (highVal + 1);
this.lookup = new Uint8Array(length);

if (lookup instanceof BaseStream) {
Expand Down

0 comments on commit 1c0c070

Please sign in to comment.