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

marshal regression with refs that alias the same object #16496

Closed
dylanagreen opened this issue Dec 29, 2020 · 0 comments · Fixed by #22983
Closed

marshal regression with refs that alias the same object #16496

dylanagreen opened this issue Dec 29, 2020 · 0 comments · Fixed by #22983

Comments

@dylanagreen
Copy link

dylanagreen commented Dec 29, 2020

Example

import marshal
import streams

type
  Obj = ref object
    i: int
    b: bool

let
  strm = newStringStream()

var
  o = Obj(i: 1, b: false)
  t1 = @[o, o]
  t2: seq[Obj]

doAssert t1[0] == t1[1]

strm.store(t1)
strm.setPosition(0)
strm.load(t2)
strm.close()

doAssert t2[0] == t2[1]

Current Output

src/example.nim(21) example
.choosenim/toolchains/nim-#devel/lib/pure/marshal.nim(279) load
.choosenim/toolchains/nim-#devel/lib/pure/marshal.nim(266) loadAny
.choosenim/toolchains/nim-#devel/lib/pure/marshal.nim(186) loadAny
.choosenim/toolchains/nim-#devel/lib/pure/marshal.nim(204) loadAny
.choosenim/toolchains/nim-#devel/lib/core/typeinfo.nim(274) setPointer
.choosenim/toolchains/nim-#devel/lib/system/assign.nim(111) genericAssign
.choosenim/toolchains/nim-#devel/lib/system/assign.nim(106) genericAssignAux
.choosenim/toolchains/nim-#devel/lib/system/gc.nim(251) unsureAsgnRef
.choosenim/toolchains/nim-#devel/lib/system/gc.nim(184) incRef
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Expected Output

Nothing.

Additional Information

If o = Obj(i: 1, b: false) is replaced with o = Obj(), the above segfault will not occur. Instead, the marshaling will appear to succeed, but the second assertion will fail. The example code will run without issues if Obj is an object rather than a ref object. This may be related to issue #15934.

This code runs without issue in 1.2.6, but fails in 1.2.8 and devel.

git bisect on the version-1-2 branch indicates that the first bad commit is 2624de0

Output of nim -v for above stacktrace:

Nim Compiler Version 1.5.1 [MacOSX: amd64]
Compiled at 2020-12-22
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 297c8e403d110dd872e070563328f4e0c734cd01
dylanagreen added a commit to dylanagreen/chrysaora that referenced this issue Dec 29, 2020
viega pushed a commit to viega/Nim that referenced this issue Nov 26, 2023
Araq pushed a commit that referenced this issue Nov 26, 2023
Fixes #16496 

![Marshal doesn't properly unmarshal *most* ref objects; the exceptions
being nil
ones](https://github-production-user-asset-6210df.s3.amazonaws.com/4764481/285471431-a39ee2c5-5670-4b12-aa10-7a10ba6b5b96.gif)
Test case added.

Note that this test (t9754) does pass locally, but there are tons of
failures by default on OS X arm64, mostly around the bohem GC, so it's
pretty spammy, and could easily have missed something. If there are
better instructions please do let me know.

---------

Co-authored-by: John Viega <[email protected]>
Co-authored-by: John Viega <[email protected]>
Co-authored-by: ringabout <[email protected]>
narimiran pushed a commit that referenced this issue Apr 18, 2024
Fixes #16496

![Marshal doesn't properly unmarshal *most* ref objects; the exceptions
being nil
ones](https://github-production-user-asset-6210df.s3.amazonaws.com/4764481/285471431-a39ee2c5-5670-4b12-aa10-7a10ba6b5b96.gif)
Test case added.

Note that this test (t9754) does pass locally, but there are tons of
failures by default on OS X arm64, mostly around the bohem GC, so it's
pretty spammy, and could easily have missed something. If there are
better instructions please do let me know.

---------

Co-authored-by: John Viega <[email protected]>
Co-authored-by: John Viega <[email protected]>
Co-authored-by: ringabout <[email protected]>
(cherry picked from commit 5b2fcab)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant