ContestNode.Ref: panic: switch on corrupt value #11

Open
opened 2026-04-09 15:05:57 +02:00 by maleszka · 0 comments
Owner
thread 381813 panic: switch on corrupt value
/home/maleszka/projects/wbij/src/api/platforms/satori.zig:55:59: 0x10a0a0b in fetchContestNodeAndSome (wbij)
        const contest_ref: data.ContestNode.Ref = switch (ref.kind) {
                                                          ^
/home/maleszka/projects/wbij/src/api/platforms.zig:130:68: 0x107ecaa in fetchNodeToInbox (wbij)
            inline else => |*impl| try impl.fetchContestNodeAndSome(arena, @bitCast(ref), ancestors),
                                                                   ^
/home/maleszka/projects/wbij/src/api/fetcher/ContestGraph.zig:240:34: 0x10648e3 in update (wbij)
            self.fetchNodeToInbox(inbox, ref) catch |err| switch (err) {
                                 ^
/home/maleszka/projects/wbij/src/api/fetcher/ContestGraph.zig:92:20: 0x105978b in fetch (wbij)
    try self.update(&inbox, progress);
                   ^
/home/maleszka/projects/wbij/src/main.zig:112:20: 0x10552fc in main (wbij)
    try graph.fetch(progress);

logic backend in wbij is designed in such a way that whenever some cache entry is incorrect (corrupted, altered by user, whatever), this entry (relation tuple) should be discarded and redownloaded by the appropriate fetcher

The problem currently is that ContestNode.Ref can be any u64 (so any 64 bits) but in both sim and satori implementation, they are bitCasted to a packed struct, whose one of the fields is enum. It means that not all 64bit sequences are valid. Currently, wbij crashes on invalid ref (which is better than silently continuing) but I believe it should at least result in an error (cause then we can safely free resources, etc.)

``` thread 381813 panic: switch on corrupt value /home/maleszka/projects/wbij/src/api/platforms/satori.zig:55:59: 0x10a0a0b in fetchContestNodeAndSome (wbij) const contest_ref: data.ContestNode.Ref = switch (ref.kind) { ^ /home/maleszka/projects/wbij/src/api/platforms.zig:130:68: 0x107ecaa in fetchNodeToInbox (wbij) inline else => |*impl| try impl.fetchContestNodeAndSome(arena, @bitCast(ref), ancestors), ^ /home/maleszka/projects/wbij/src/api/fetcher/ContestGraph.zig:240:34: 0x10648e3 in update (wbij) self.fetchNodeToInbox(inbox, ref) catch |err| switch (err) { ^ /home/maleszka/projects/wbij/src/api/fetcher/ContestGraph.zig:92:20: 0x105978b in fetch (wbij) try self.update(&inbox, progress); ^ /home/maleszka/projects/wbij/src/main.zig:112:20: 0x10552fc in main (wbij) try graph.fetch(progress); ``` logic backend in wbij is designed in such a way that whenever some cache entry is incorrect (corrupted, altered by user, whatever), this entry (relation tuple) should be discarded and redownloaded by the appropriate fetcher The problem currently is that `ContestNode.Ref` can be any `u64` (so any 64 bits) but in both sim and satori implementation, they are bitCasted to a packed struct, whose one of the fields is enum. It means that _not all 64bit sequences are valid_. Currently, `wbij` crashes on invalid ref (which is better than silently continuing) but I believe it should at least result in an error (cause then we can safely free resources, etc.)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
maleszka/wbij#11
No description provided.