Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic in dlmalloc after upgrading to Rust 1.78.0 #1389

Open
jtroo opened this issue May 7, 2024 · 12 comments
Open

Panic in dlmalloc after upgrading to Rust 1.78.0 #1389

jtroo opened this issue May 7, 2024 · 12 comments

Comments

@jtroo
Copy link

jtroo commented May 7, 2024

🐛 Bug description

After upgrading to Rust toolchain 1.78.0, I started getting this error in my GitHub pages project when compiling to wasm:

panicked at /rust/deps/dlmalloc-0.2.6/src/dlmalloc.rs:1198:13:
assertion failed: psize <= size + max_overhead

Compiling with the exact same code, this does not happen with 1.77.1.

🤔 Expected Behavior

No panic

👟 Steps to reproduce

Code compiled to wasm:

Command used to build:

wasm-pack build --target web

The .wasm output is being served in https://github.com/jtroo/jtroo.github.io, which can easily be served locally, e.g.

PS G:\repos\jtroo.github.io> python -m http.server 9000

🌍 Your environment

Include the relevant details of your environment.
wasm-pack version: 0.12.1
rustc version: 1.78.0 / 1.77.1

@jtroo
Copy link
Author

jtroo commented May 7, 2024

Happy to help debug/investigate further with some pointers for where to look to generate more info

@FredrikNoren
Copy link

We're seeing it here too, but doesn't seem to help to downgrade to rust 1.77.1.
The bug appeared a few days ago. Is it one of the dependencies to wasm-pack that has changed?

@SFBdragon
Copy link

SFBdragon commented May 8, 2024

Just want to link some details here too:

alexcrichton/dlmalloc-rs#41 (comment)

alexcrichton/dlmalloc-rs#41 (comment)

In summary, after 1.78 enabled debug assertions in dlmalloc, allocating and deallocating with a different size (this is UB) is caught instead of "silently working" (because of how dlmalloc works, specifically, other allocators will often crash as they actually rely on the safety contract).

@elpiel
Copy link

elpiel commented May 9, 2024

This issue seems to be resolved in latest main and 0.2.92 version, will paste my comment on the issue I opened in dlmalloc: alexcrichton/dlmalloc-rs#41

For anyone landing on this issue, it seems that in the latest revision on main this issue has been fixed.
In the changelog on wasm-bindgen I see this bugfix related to UB in String deallocation, since we were using an older version of wasm-bindgen (because last time we tried to upgrade it was breaking our app again :D )

Fixed UB when freeing strings received from JS if not using the default allocator. rustwasm/wasm-bindgen#3808

https://github.com/rustwasm/wasm-bindgen/blob/0.2.92/CHANGELOG.md#fixed-1

OR

Take alignment into consideration during (de/re)allocation. rustwasm/wasm-bindgen#3463

https://github.com/rustwasm/wasm-bindgen/blob/0.2.92/CHANGELOG.md#0287

rustwasm/wasm-bindgen#3463

@cryptolake
Copy link

Just For anyone who is still stuck, I solved this by downgrading back to 1.76 .

sharkdp added a commit to sharkdp/numbat that referenced this issue Jul 1, 2024
@DLillard0
Copy link

same error

@jollygreenlaser
Copy link

I upgraded to 0.2.93 while on latest nightly and this issue seems gone. It seems the version upgrade to 0.2.92 or higher is the fix, though I don't have any way to test on stable.

@Terkwood
Copy link

Terkwood commented Nov 3, 2024

Upgrading wasm-bindgen to latest worked for me

@nbittich
Copy link

nbittich commented Dec 8, 2024

same error, rust 1.83 and wasm-bindgen 0.2.99:


panicked at /rust/deps/dlmalloc-0.2.6/src/dlmalloc.rs:1198:13:
assertion failed: psize <= size + max_overhead

Stack:

__wbg_get_imports/imports.wbg.__wbg_new_8a6f238a6ece86ea@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm.js:228:21
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[2540]:0xd680d
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[588]:0x9ee73
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[1797]:0xc79bb
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[1424]:0xbdbce
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[2301]:0xd1ef0
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[1735]:0xc4275
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[913]:0xaedad
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[34]:0x99ac
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[34]:0xd3b4
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[34]:0xd3b4
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[34]:0xd3b4
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[34]:0xd3b4
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[34]:0xd3b4
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[34]:0xd3b4
@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:wasm-function[462]:0x950b6
html_to_rdfa@https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm.js:143:14
run/<@https://nbittich.github.io/graph-rdfa-processor/app.js:40:27
EventListener.handleEvent*run@https://nbittich.github.io/graph-rdfa-processor/app.js:37:8
async*@https://nbittich.github.io/graph-rdfa-processor/app.js:90:1


<anonymous code>:1:145535
    overrideMethod <anonymous code>:1
    __wbg_error_7534b8e9a36f1ab4 https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm.js:211
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:878732
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:650867
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:817595
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:777166
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:859888
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:803445
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:716205
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:39340
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:54196
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:54196
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:54196
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:54196
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:54196
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:54196
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm_bg.wasm:610486
    html_to_rdfa https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm.js:143
    run https://nbittich.github.io/graph-rdfa-processor/app.js:40
    (Async: EventListener.handleEvent)
    run https://nbittich.github.io/graph-rdfa-processor/app.js:37
    <anonymous> https://nbittich.github.io/graph-rdfa-processor/app.js:90
Uncaught RuntimeError: unreachable executed
    html_to_rdfa https://nbittich.github.io/graph-rdfa-processor/pkg/rdfa_wasm.js:143
    run https://nbittich.github.io/graph-rdfa-processor/app.js:40
    run https://nbittich.github.io/graph-rdfa-processor/app.js:37
    async* https://nbittich.github.io/graph-rdfa-processor/app.js:90
rdfa_wasm_bg.wasm:650903:1
Source map error: Error: request failed with status 404
Resource URL: https://nbittich.github.io/graph-rdfa-processor/%3Canonymous%20code%3E
Source Map URL: installHook.js.map
Source map error: request failed with status 404
Resource URL: https://nbittich.github.io/graph-rdfa-processor/%3Canonymous%20code%3E
Source Map URL: installHook.js.map

@SFBdragon
Copy link

Another crate with broken allocator behavior? Glad to see WASM is as debuggable as ever though ^-^

I often write a shim allocator to log/test for allocation behavior. I haven't tried it before, but I wonder if https://lib.rs/crates/checkers could provide some more info.

(Typically, it's just a matter of finding out which crate and calls are doing unsafe allocation management badly. Unfortunately I don't think I'll have the time to dig into this one in the near future.)

@nbittich
Copy link

nbittich commented Dec 8, 2024

I'd be happy to provide test case and source code to reproduce the bug, forgot to mention but the issue is (at least) in the web target. I for now switched to the lol_alloc and it works as expected. Here's the commit where I did the switch:
nbittich/graph-rdfa-processor@db8a635

Here's the payload you can use in the html textarea (https://nbittich.github.io/graph-rdfa-processor/)

<html>

<head>
    <title>Notulen</title>
</head>

<body
    prefix='eli: http://data.europa.eu/eli/ontology# prov: http://www.w3.org/ns/prov# mandaat: http://data.vlaanderen.be/ns/mandaat# besluit: http://data.vlaanderen.be/ns/besluit# ext: http://mu.semte.ch/vocabularies/ext/ person: http://www.w3.org/ns/person# foaf: http://xmlns.com/foaf/0.1/ lblodlg: http://data.lblod.info/vocabularies/leidinggevenden/ skos: http://www.w3.org/2004/02/skos/core# persoon: https://data.vlaanderen.be/ns/persoon# dc: http://purl.org/dc/terms/ '>
    <div id="editor" class="ember-application">
        <div class="editor">
            <div id="ember245" class="editor__paper ember-view">
                <div>
                    <div class='ext_metadata' contenteditable='false' property='ext:metadata'>
                        <div typeof='besluit:Zitting'
                            resource='https://data.destelbergen.be/zittingen/8b9fe347-4c93-ee11-be37-000d3ad8b15b'>
                            <span property='besluit:heeftNotulen'
                                resource='https://destelbergen.powerappsportals.com/zittingen/?id=a6a451c4-601f-ef11-840a-002248a03ee0'
                                typeof='foaf:Document'></span>
                            <span property='eli:passed_by'
                                resource='http://data.lblod.info/id/bestuursorganen/cd9ddb549bfc87477be14071944f0bcae5a468aa2e912dd59f1534d9e28f871a'
                                typeof='besluit:Bestuursorgaan'></span>
                            <div class='container'>
                                <div class='row py-3'>
                                    <div class='col'><img
                                            src='https://www.destelbergen.be/sites/default/files/2023-01/dest-logo_0.svg'
                                            style='max-width:250px'></div>
                                    <div class='col'>
                                        <h6 class='text-uppercase text-right'>Notulen</h6>
                                    </div>
                                </div>
                                <div class='row'>
                                    <div class='col'>
                                        <h1 class='text-uppercase text-center'>Gemeenteraad</h1>
                                    </div>
                                </div>
                                <div class='row py-3'>
                                    <div class='col'>
                                        <p id='ccp_publisheddate'></p>
                                    </div>
                                    <div class='col'>
                                        <h6 class='text-right' property='dc:title'
                                            id='8b9fe347-4c93-ee11-be37-000d3ad8b15b'>
                                            <span
                                                resource='http://data.lblod.info/id/bestuursorganen/cd9ddb549bfc87477be14071944f0bcae5a468aa2e912dd59f1534d9e28f871a'
                                                typeof='besluit:Bestuursorgaan'
                                                property='besluit:isGehoudenDoor'></span>
                                            Zitting van <span property='besluit:geplandeStart'
                                                content='2024-04-18T17:46:39Z' datatype='xsd:dateTime'>donderdag 18
                                                april 2024</span>
                                            <span class='annotation' property='prov:atLocation' datatype='xsd:string'
                                                content='Destelbergen'></span>
                                            <span property='prov:startedAtTime' datatype='xsd:dateTime'
                                                content='2024-04-18T17:46:39Z'></span>
                                            <span property='prov:endedAtTime' datatype='xsd:dateTime'
                                                content='2024-04-18T19:00:00Z'></span>
                                        </h6>
                                    </div>
                                </div>
                                <div class='row py-5'>
                                    <div class='col'>
                                        <p property='ext:insertAanwezigenText'>
                                            <span class='font-weight-bold'>Aanwezig: </span>
                                            <span property='besluit:heeftVoorzitter'
                                                resource='http://data.lblod.info/id/mandatarissen/5F33F82AF9D30200080002C5'
                                                typeof='mandaat:Mandataris'>Ben D'Haene</span>
                                        </p>
                                    </div>
                                </div>


                                <div class='row'>
                                    <div class='col'>
                                        <h4>Stemmingen</h4>
                                        <p>
                                            <span class='font-weight-bold'>Aanwezig: </span>
                                            <span property='besluit:heeftAanwezige'
                                                resource='http://data.lblod.info/id/mandatarissen/5D69204AA3ACB6000900033B'
                                                typeof='mandaat:Mandataris'>
                                                <span property='mandaat:isBestuurlijkeAliasVan' resource=''
                                                    typeof='person:Person'>
                                                    <span property='persoon:gebruikteVoornaam'>Henriette</span>
                                                    <span property='foaf:familyName'>Scheire</span>
                                                </span>(
                                                <span property='org:holds'
                                                    resource='http://data.lblod.info/id/mandaten/387293fe1088c6291c86a2f60cd4133c86cc464ed0e54b9ceaf12d04b5ff1f23'
                                                    typeof='mandaat:Mandaat'>
                                                    <span property='org:role'
                                                        resource='http://data.vlaanderen.be/id/concept/BestuursfunctieCode/5ab0e9b8a3b2ca7c5e000011'
                                                        typeof='skos:Concept'>
                                                        <span property='skos:prefLabel'>Gemeenteraadslid
                                                        </span>
                                                    </span>
                                                </span>)</span>,
                                            <br />
                                        </p>
                                        <br />
                                    </div>
                                </div>
                            </div>

                        </div>

                    </div>

                </div>

            </div>

        </div>

    </div>


</body>

</html>

@SFBdragon
Copy link

SFBdragon commented Dec 8, 2024

I for now switched to the lol_alloc and it works as expected.

When it comes to bad deallocations/reallocations, last time I checked, lol_alloc would "leak" memory (I.e. lose track of parts of its allocation arena). Not sure if it's possible to corrupt memory by supplying the wrong allocation Layout to lol_alloc - never heard of it happening. Regardless, just something to watch out for.

dlmalloc checks that the allocations are reasonable, if not, panics. talc will run into weird panics, so will galloc. lol_alloc silently does wrong things. They all have their different behavior for various reasons. Either way, the code has UB and demons could be flying out of your nostrils, but in practice using lol_alloc while someone fixes their code is probably fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants