Skip to content

nix::parseDump does not require str("contents") after str("regular") #14151

@myclevorname

Description

@myclevorname

Describe the bug

In the function parse in src/libutil/archive.cc, the if at line 191 does not have an else branch, leading to the string being ignored.

Steps To Reproduce

  1. Run the following script using zig run and pump its contents into a file.
const std = @import("std");

pub fn main() !void {
    var sw = std.fs.File.stdout().writer(&.{});
    const writer = &sw.interface;
    try writer.writeAll(archive);
}

inline fn str(comptime s: []const u8) []const u8 {
    return std.mem.asBytes(&std.mem.nativeToLittle(u64, s.len)) ++
        s ++ &@as([padding(s.len)]u8, @splat(0));
}

inline fn padding(comptime l: u64) u3 {
    return @truncate(-%l);
}

const archive = blk: {
    var cur: []const u8 = "";
    for (tokens) |t| cur = cur ++ str(t);
    break :blk cur;
};

const tokens: []const []const u8 = &.{
    "nix-archive-1",
    "(",
    "type",
    "regular",
    //"executable", "",
    "AAAAAAAA", // something other than "contents" or "executable"
    ")",
};
  1. Run nix nar cat ARCHIVE / on the resulting archive
[clevor@clevor-laptop-nixos:/tmp/clevor/bruh]$ zig run create.zig > archive.nar
[clevor@clevor-laptop-nixos:/tmp/clevor/bruh]$ nix nar cat archive.nar /
[clevor@clevor-laptop-nixos:/tmp/clevor/bruh]$ echo $?
0

Expected behavior

[clevor@clevor-laptop-nixos:/tmp/clevor/bruh]$ nix nar cat archive.nar /
error: bad archive: expected tag 'contents', got 'AAAAAAAA'

Metadata

nix-env (Nix) 2.28.5

Additional context

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugregressionSomething doesn't work anymore

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions