digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

json-ld playground crashes on this file #440

Open jakubklimek opened 3 years ago

jakubklimek commented 3 years ago

When I put this file in JSON-LD Playground (running json-ld.js), it freezes and crashes:

{
    "@context": [
        {
            "@version": 1.1,
            "@import": "https://ofn.gov.cz/věc/2020-07-01/kontexty/věc.jsonld",
            "@propagate": true,
            "nedefinováno": "https://slovník.gov.cz/nedefinováno/",
            "místa": "https://slovník.gov.cz/generický/pracovní-místa/pojem/",
            "Pracovní místo ve vědě a výzkumu": {
                "@id": "nedefinováno:pracovní-místo-ve-vědě-a-výzkumu",
                "@context": {
                    "pracoviště": {
                        "@id": "místa:má-pracoviště",
                        "@context": "https://pod-test.mvcr.gov.cz/otevřené-formální-normy/věda-a-výzkum/draft/kontexty/věda-a-výzkum.jsonld"
                    }
                }
            }
        }
    ],
    "typ": [
        "Pracovní místo ve vědě a výzkumu"
    ],
    "iri": "https://data.mff.cuni.cz/zdroj/pracovní-místa-mff-uk/202008-AP1-KSI",
    "pracoviště": {
        "typ": "Pracoviště",
        "iri": "https://data.mff.cuni.cz/zdroj/číselník/organizační-struktura/oddělení/204"
    }
}

In the network tab of chrome, there is a request pending, nevertheless, the requested resource is accessible, so that is not the issue: image

davidlehn commented 3 years ago

Yes it will lock up the browser and Node.js. Node.js eventually runs out of memory and aborts. It's likely something recursive due to the way @import and @context are used. I started to try and reduce to a small test case since dealing with the current 8 files is a bit much.

I'm guessing this is similar to an older issue but the fix didn't catch this edge case. Or perhaps it's a regression. https://github.com/digitalbazaar/jsonld.js/issues/358 https://github.com/digitalbazaar/jsonld.js/pull/381

I'm not sure what the best fix is until this is dealt with. I'm also not sure if the fix in this case will result in the data working or if it's an error.

@gkellogg I tried this on your distiller but it fails with "URI must be ascii only". Perhaps the test suite needs some tests to check URI encodings work the same across implementations? jsonld.js 4.x Node.js loader uses the old request library and fails with ERR_UNESCAPED_CHARACTERS. v5 will be using fetch API at a low level and it handles these URIs fine. Seems the browser XHR loader handles them too. That being said, at some point I'll have a simplified test case for this recursion issue that should work everywhere.