xmllint-wasm icon indicating copy to clipboard operation
xmllint-wasm copied to clipboard

Invalid array length on "large xml" file

Open nunomarks opened this issue 11 months ago • 8 comments

There seems to be a limit on the size of the XML that the tool can validate. The following error in thrown for a "large XML file":

RangeError [Error]: Invalid array length

I was able to reproduce the issue on an XML file that surpasses 134_217_724 bytes, or in hex, 0x7FFFFFC. Seems like a weird limit though, but pretty sure this is not an xmllint issue, as I'm able to validate the file via command line.

Is it possible to take a look at this issue?

nunomarks avatar Mar 18 '24 10:03 nunomarks

I could take a look, but I'd need to be able to reproduce the error first.

Can you post the output of

npm version

Are you running on Mac, Windows or Linux, and if on Mac, is it Intel or M1 or M2?

This doesn't look like a mermory limit issue per se, but you could try raising the max memory limit

const {validateXML, memoryPages} = require('xmllint-wasm');

validateXML({
    ...
    maxMemoryPages: xmllint.memoryPages.GiB,

noppa avatar Mar 18 '24 11:03 noppa

npm version
{
  npm: '10.2.4',
  node: '20.11.1',
  acorn: '8.11.2',
  ada: '2.7.4',
  ares: '1.20.1',
  base64: '0.5.1',
  brotli: '1.0.9',
  cjs_module_lexer: '1.2.2',
  cldr: '43.1',
  icu: '73.2',
  llhttp: '8.1.1',
  modules: '115',
  napi: '9',
  nghttp2: '1.58.0',
  nghttp3: '0.7.0',
  ngtcp2: '0.8.1',
  openssl: '3.0.13+quic',
  simdutf: '4.0.4',
  tz: '2023c',
  undici: '5.28.3',
  unicode: '15.0',
  uv: '1.46.0',
  uvwasi: '0.0.19',
  v8: '11.3.244.8-node.17',
  zlib: '1.2.13.1-motley-5daffc7'
}

Are you running on Mac, Windows or Linux, and if on Mac, is it Intel or M1 or M2?

Mac Apple M1 Pro

This doesn't look like a memory limit issue per se, but you could try raising the max memory limit

I did that and increased to the maximum memory possible before creating this issue (and it didn't work), so you are right, it's not a memory limit issue.

nunomarks avatar Mar 18 '24 11:03 nunomarks

Thanks, I don't have a Mac available but I'll try to reproduce with the other environment specs

noppa avatar Mar 18 '24 13:03 noppa

Thanks, I don't have a Mac available but I'll try to reproduce with the other environment specs

Happy to provide you anything else you might need to help you reproduce it. I attached the XML I used to test.

very-large.xml.zip

nunomarks avatar Mar 18 '24 15:03 nunomarks

Thanks for the test XML, I was able to reproduce the issue.

I have a possible (not yet very well tested) fix, here: v5.0.0-alpha (PR #21). Could you test with this prerelease version, e.g. by installing it with

npm i xmllint-wasm@https://github.com/noppa/xmllint-wasm/releases/download/v5.0.0-alpha/xmllint-wasm.tgz

noppa avatar Mar 19 '24 10:03 noppa

The solution from #21 works. I have tested with several large XMLs (all UTF-8 encoded) and everything is flawless 👌

nunomarks avatar Mar 19 '24 11:03 nunomarks

Sweet. I'm a bit busy for a few days but will try to test and craft a proper release soonish. Meanwhile, the github alpha release should work fine.

noppa avatar Mar 19 '24 18:03 noppa

This is also now in npm, with version 5.0.0-rc.0. I'll also test this in prod a bit before I dare to tag that as the latest release.

noppa avatar Apr 14 '24 18:04 noppa