Re: [PATCH bpf-next v2 1/3] libbpf: Implement basic zip archive parsing support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 21, 2023 at 3:45 PM Daniel Müller <deso@xxxxxxxxxx> wrote:
>
> This change implements support for reading zip archives, including
> opening an archive, finding an entry based on its path and name in it,
> and closing it.
> The code was copied from https://github.com/iovisor/bcc/pull/4440, which
> implements similar functionality for bcc. The author confirmed that he
> is fine with this usage and the corresponding relicensing. I adjusted it
> to adhere to libbpf coding standards.
>
> Signed-off-by: Daniel Müller <deso@xxxxxxxxxx>
> Acked-by: Michał Gregorczyk <michalgr@xxxxxxxx>
> ---
>  tools/lib/bpf/Build |   2 +-
>  tools/lib/bpf/zip.c | 326 ++++++++++++++++++++++++++++++++++++++++++++
>  tools/lib/bpf/zip.h |  47 +++++++
>  3 files changed, 374 insertions(+), 1 deletion(-)
>  create mode 100644 tools/lib/bpf/zip.c
>  create mode 100644 tools/lib/bpf/zip.h
>

[...]

> +
> +static int find_cd(struct zip_archive *archive)
> +{
> +       __u32 offset;
> +       int64_t limit;
> +       int rc = -1;
> +
> +       if (archive->size <= sizeof(struct end_of_cd_record))
> +               return -EINVAL;
> +
> +       /* Because the end of central directory ends with a variable length array of
> +        * up to 0xFFFF bytes we can't know exactly where it starts and need to
> +        * search for it at the end of the file, scanning the (limit, offset] range.
> +        */
> +       offset = archive->size - sizeof(struct end_of_cd_record);
> +       limit = (int64_t)offset - (1 << 16);
> +
> +       for (; offset >= 0 && offset > limit && rc == -1; offset--)

rc != 0 here to handle -EINVAL? It will keep going for -ENOTSUP,
though, which is probably not right, so maybe (rc != 0 && rc !=
-ENOTSUP)?

but with the latter it feels better to just have explicit if with
return inside the for loop

> +               rc = try_parse_end_of_cd(archive, offset);
> +
> +       return rc;
> +}
> +

[...]




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux