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

Segfault when parsing a List (Str, Dec) #38

Open
ageron opened this issue Sep 7, 2024 · 1 comment
Open

Segfault when parsing a List (Str, Dec) #38

ageron opened this issue Sep 7, 2024 · 1 comment

Comments

@ageron
Copy link

ageron commented Sep 7, 2024

I'm trying to add the rest-api exercise to the roc track on exercism. It involves parsing a JSON object containing a Dict, but unfortunately this is blocked by #33 . I thought I could work around this by replacing the Dict Str Dec with a List (Str, Dec). Unfortunately, I'm now running into a segfault.

Here's a code example to reproduce the issue (I'm using roc nightly pre-release, built from commit 54cd967 on Fri Sep 6 09:02:04 UTC 2024):

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br",
    json: "https://github.com/lukewilliamboswell/roc-json/releases/download/0.10.2/FH4N0Sw-JSFXJfG3j54VEDPtXOoN-6I9v_IA8S18IGk.tar.br",
}

import json.Json

main =
    Task.ok {}

ListOfTuples: List (Str, Dec)

expect
    jsonStr = "[[\"Alice\", 1.1], [\"Bob\", 2.2], [\"Charles\", 3.3]]"
    result : Result ListOfTuples _
    result = jsonStr |> Str.toUtf8 |> Decode.fromBytes Json.utf8
    result == Ok [("Alice", 1.1), ("Bob", 2.2), ("Charles", 3.3)]
@Anton-4
Copy link
Contributor

Anton-4 commented Sep 7, 2024

Thanks for reporting this @ageron!

I've converted this to an app to facilitate investigation:

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br",
    json: "https://github.com/lukewilliamboswell/roc-json/releases/download/0.10.2/FH4N0Sw-JSFXJfG3j54VEDPtXOoN-6I9v_IA8S18IGk.tar.br"
}

import pf.Stdout
import json.Json

ListOfTuples: List (Str, Dec)

jsonStr = "[[\"Alice\", 1.1], [\"Bob\", 2.2], [\"Charles\", 3.3]]"

result : Result ListOfTuples _
result = jsonStr |> Str.toUtf8 |> Decode.fromBytes Json.utf8

main =
    Stdout.line! (Inspect.toStr result)

Valgrind output with the legacy linker:

❯ valgrind ./examples/helloWorld 
==21969== Memcheck, a memory error detector
==21969== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==21969== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==21969== Command: ./examples/helloWorld
==21969== 
==21969== Invalid read of size 8
==21969==    at 0x147E33: ??? (roc_app:0)
==21969==    by 0x148F70: ??? (roc_app:0)
==21969==    by 0x144B8F: List_walkHelp_dbefccae6de790f8e3497ad3c6c1c58a12a744edb0d65ec1ec4ade8b1151a59b (roc_app:0)
==21969==    by 0x13AB00: List_walk_52aff1341cf42f5e6559a2cf028663f7bbbc7576ac1948fc58784a0613b79 (roc_app:0)
==21969==    by 0x12FEAA: Inspect_158_d9e2d7d318b97522751e8d862a897cd552d26040fa25d41678f9ac7b36cd7 (roc_app:0)
==21969==    by 0x145C00: Inspect_156_35d6cb78c74f84df82ab12c37bc71bbe5193f93e9d36506abc7c9c8ca124d1ab (roc_app:0)
==21969==    by 0x136BB3: Inspect_apply_5eb6a2599d3097c754d93922b84522fd22c626afbfca9a48d724fa1945e3ca9 (roc_app:0)
==21969==    by 0x12FDD0: #Derived_custom8_52459ae5e05017996bb4298dd9ac3944ffe997fa2e2ad98ba6fd7348395f63 (roc_app:0)
==21969==    by 0x13CB5E: Inspect_apply_8e7a40fb7cb2175e9c8b7aee60f44cef84959b742d3a14c483b6e3b14f05c2f (roc_app:0)
==21969==    by 0x13458D: Inspect_213_3994ebd10847f51a1ba443e4f3b9fb75da3f81a354da59de9bd34aaa2e927d (roc_app:0)
==21969==    by 0x139E8A: Inspect_210_a51293a4c3ce80beb92fd22c82b6b69bd26ee8bc815b483e3cf291f486236c (roc_app:0)
==21969==    by 0x1399EC: List_walkHelp_1971ed175c5339d8a493ee2a719f3ca8f50fbcc2a26feaf7b54a27898e3f (roc_app:0)
==21969==  Address 0xfffffffffffffff8 is not stack'd, malloc'd or (recently) free'd
==21969== 
==21969== 
==21969== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==21969==  Access not within mapped region at address 0xFFFFFFFFFFFFFFF8
==21969==    at 0x147E33: ??? (roc_app:0)
==21969==    by 0x148F70: ??? (roc_app:0)
==21969==    by 0x144B8F: List_walkHelp_dbefccae6de790f8e3497ad3c6c1c58a12a744edb0d65ec1ec4ade8b1151a59b (roc_app:0)
==21969==    by 0x13AB00: List_walk_52aff1341cf42f5e6559a2cf028663f7bbbc7576ac1948fc58784a0613b79 (roc_app:0)
==21969==    by 0x12FEAA: Inspect_158_d9e2d7d318b97522751e8d862a897cd552d26040fa25d41678f9ac7b36cd7 (roc_app:0)
==21969==    by 0x145C00: Inspect_156_35d6cb78c74f84df82ab12c37bc71bbe5193f93e9d36506abc7c9c8ca124d1ab (roc_app:0)
==21969==    by 0x136BB3: Inspect_apply_5eb6a2599d3097c754d93922b84522fd22c626afbfca9a48d724fa1945e3ca9 (roc_app:0)
==21969==    by 0x12FDD0: #Derived_custom8_52459ae5e05017996bb4298dd9ac3944ffe997fa2e2ad98ba6fd7348395f63 (roc_app:0)
==21969==    by 0x13CB5E: Inspect_apply_8e7a40fb7cb2175e9c8b7aee60f44cef84959b742d3a14c483b6e3b14f05c2f (roc_app:0)
==21969==    by 0x13458D: Inspect_213_3994ebd10847f51a1ba443e4f3b9fb75da3f81a354da59de9bd34aaa2e927d (roc_app:0)
==21969==    by 0x139E8A: Inspect_210_a51293a4c3ce80beb92fd22c82b6b69bd26ee8bc815b483e3cf291f486236c (roc_app:0)
==21969==    by 0x1399EC: List_walkHelp_1971ed175c5339d8a493ee2a719f3ca8f50fbcc2a26feaf7b54a27898e3f (roc_app:0)
==21969==  If you believe this happened as a result of a stack
==21969==  overflow in your program's main thread (unlikely but
==21969==  possible), you can try to increase the size of the
==21969==  main thread stack using the --main-stacksize= flag.
==21969==  The main thread stack size used in this run was 8388608.
==21969== 
==21969== HEAP SUMMARY:
==21969==     in use at exit: 504 bytes in 6 blocks
==21969==   total heap usage: 12 allocs, 6 frees, 1,008 bytes allocated
==21969== 
==21969== LEAK SUMMARY:
==21969==    definitely lost: 0 bytes in 0 blocks
==21969==    indirectly lost: 0 bytes in 0 blocks
==21969==      possibly lost: 480 bytes in 5 blocks
==21969==    still reachable: 24 bytes in 1 blocks
==21969==         suppressed: 0 bytes in 0 blocks
==21969== Rerun with --leak-check=full to see details of leaked memory
==21969== 
==21969== For lists of detected and suppressed errors, rerun with: -s
==21969== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)

This valgrind output is similar to parts of roc-lang/roc#6813, these issues could have the same cause.

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

2 participants