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

SigMD5 ending in zeroes are truncated #44

Closed
eredwine opened this issue Oct 4, 2023 · 6 comments
Closed

SigMD5 ending in zeroes are truncated #44

eredwine opened this issue Oct 4, 2023 · 6 comments

Comments

@eredwine
Copy link
Contributor

eredwine commented Oct 4, 2023

Currently the UBI8 libuuid rpm has an SIGMD5 value of c1e561f13d39aee443a1f00258fba000.

rpm -qa --queryformat "\{Name: \"%{NAME}\", Digest: \"md5:%{SIGMD5}\"\}\n"
{Name: "libuuid", Digest: "md5:c1e561f13d39aee443a1f00258fba000"}

but the SIGMD5 value is loaded as c1e561f13d39aee443a1f00258fba0.

package main

import (
	"fmt"
	"log"

	rpmdb "github.com/knqyf263/go-rpmdb/pkg"
)

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}

func run() error {
	db, err := rpmdb.Open("./Packages")
	if err != nil {
		return err
	}
	pkgList, err := db.ListPackages()
	if err != nil {
		return err
	}

	fmt.Println("Packages:")
	for _, pkg := range pkgList {
		fmt.Printf("\t%+s %+s\n", *&pkg.Name, *&pkg.SigMD5)
	}

	fmt.Printf("[Total Packages: %d]\n", len(pkgList))
	return nil
}
./package-checker 
Packages:
        libuuid c1e561f13d39aee443a1f00258fba0
[Total Packages: 1]

The attached Packages.zip file contains the libuuid rpm that is experiencing the error.

@knqyf263
Copy link
Owner

knqyf263 commented Oct 5, 2023

I think bytes.TrimRight should be replaced with bytes.TrimSuffi. I welcome contributions 👍
https://github.com/DmitriyLewen/go-rpmdb/blob/801cdbd76e632491a3be72951364749fffce5ca5/pkg/package.go#L237

@eredwine
Copy link
Contributor Author

eredwine commented Oct 6, 2023

I think bytes.TrimRight should be replaced with bytes.TrimSuffi. I welcome contributions 👍 https://github.com/DmitriyLewen/go-rpmdb/blob/801cdbd76e632491a3be72951364749fffce5ca5/pkg/package.go#L237

I don't think bytes.TrimSuffix would work either. MD5 checksums are always 16 bytes in size so any trimming would result in incomplete data.

@knqyf263
Copy link
Owner

knqyf263 commented Oct 6, 2023

It's terminated with null. Or isn't there null as it's not string?

@eredwine
Copy link
Contributor Author

eredwine commented Oct 6, 2023

Yea, I don't think there is a null since it is not a string. I checked the length of the byte slice and it is 16 bytes. So, that doesn't leave room for a null terminator since an MD5 checksum needs 16 bytes.

But, I could see doing something like ie.Data[0:16] in case there was one in some future version of the RPM spec.

@knqyf263
Copy link
Owner

knqyf263 commented Oct 8, 2023

OK

@knqyf263
Copy link
Owner

#45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants