m-labs / artiq

A leading-edge control system for quantum information experiments
https://m-labs.hk/artiq
GNU Lesser General Public License v3.0
414 stars 192 forks source link

Exceptions use deallocated memory in session.rs #2071

Closed thomasfire closed 1 year ago

thomasfire commented 1 year ago

Bug Report

One-Line Summary

Exceptions use deallocated memory in session.

Issue Details

Steps to Reproduce

Run experiment:

class KernelNestedFmtException(EnvExperiment):
    def build(self):
        self.setattr_device("core")

    @kernel
    def run(self):
        try:
            self.throw()
        except:
            try:
                raise RTIOUnderflow("{bar}")
            except:
                raise RTIOOverflow("{buzz}")

    def throw(self):
        raise CustomException("{foo}")

Expected Behavior

Exceptions would have their respective messages.

Actual (undesired) Behavior

RTIOUnderflow has {buzz message. Moreover it has the same pointer as {buzz} message.

Cause of problem

https://github.com/m-labs/artiq/blob/b225717ddbd038f40af5d3b875a5cebcda622098/artiq/firmware/runtime/session.rs#L493-L503

The msg is allocated in the same point, and CSlice doesn't own the data, so it gets overwritten on next cycle.

Your System (omit irrelevant parts)

Latest master. release-7 is not affected.

sbourdeauducq commented 1 year ago

What's the situation on Zynq?

thomasfire commented 1 year ago

What's the situation on Zynq?

There should not be such problem, since message is written to the stream in the same scope as formatting being done

https://git.m-labs.hk/M-Labs/artiq-zynq/src/commit/48721ca9cb168cf609cb65e0a36ec839e7f0a1b6/src/runtime/src/comms.rs#L270-L282