Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/core/xref.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,16 +417,20 @@ class XRef {
LT = 0x3c;

function readToken(data, offset) {
let token = "",
ch = data[offset];
while (ch !== LF && ch !== CR && ch !== LT) {
if (++offset >= data.length) {
const MAX_TOKEN_LENGTH = 0x1fffffe8;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any "magical" values/constants should always have a good comment explaining why they are needed and how they were chosen.

@akopachov akopachov Feb 23, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thank you.
I added the comment explaining where and why I picked this magic value from, but I'm open to any discussion if it should be set to some more reasonable value.

@Snuffleupagus Snuffleupagus Feb 23, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that PDF.js is first and foremost intended for browsers, using Node.js to choose that value seems a little strange.


Also, please see https://github.com/mozilla/pdf.js/wiki/Squashing-Commits

const dataLen = data.length;
const startOffset = offset;
while (offset < dataLen) {
const ch = data[offset];
if (ch === LF || ch === CR || ch === LT) {
break;
}
token += String.fromCharCode(ch);
ch = data[offset];
offset++;
}
if (offset - startOffset > MAX_TOKEN_LENGTH) {
offset = startOffset + MAX_TOKEN_LENGTH;
}
return token;
return data.subarray(startOffset, offset).toString("ascii");
}
function skipUntil(data, offset, what) {
const length = what.length,
Expand Down