Reader will now check BlockLog

This commit is contained in:
Caleb Gardner
2021-01-20 14:10:14 -06:00
parent 8dba30e24f
commit dd08d3516d
4 changed files with 14 additions and 22 deletions
+1 -7
View File
@@ -105,6 +105,7 @@ func (f *File) Sys() interface{} {
// }
//Close does nothing. It's simply here to satisfy fs.File
//TODO: add actual implementation
// func (f *File) Close() error {
// return nil
// }
@@ -293,13 +294,6 @@ func (f *File) Mode() os.FileMode {
return mode
}
//TODO: Implement with 1.16
//Type returns the type bits from fs.FileMode
// func (f *File) Type() fs.FileInfo {
// return Mod() ^&fs.ModePerm
// }
//ExtractTo extracts the file to the given path. This is the same as ExtractWithOptions(path, false, false, os.ModePerm, false).
//Will NOT try to keep symlinks valid, folders extracted will have the permissions set by the squashfs, but the folder to make path will have full permissions (777).
//
+6 -4
View File
@@ -26,6 +26,8 @@ var (
ErrOptions = errors.New("Possibly incompatible compressor options")
)
//TODO: implement fs.FS, possibly more FS types for compatibility. Most of this work will mostly be handed off to root anyway so this shouldn't be too difficult.
//Reader processes and reads a squashfs archive.
type Reader struct {
r io.ReaderAt
@@ -39,7 +41,6 @@ type Reader struct {
//NewSquashfsReader returns a new squashfs.Reader from an io.ReaderAt
func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
hasUnsupportedOptions := false
var rdr Reader
rdr.r = r
err := binary.Read(io.NewSectionReader(rdr.r, 0, int64(binary.Size(rdr.super))), binary.LittleEndian, &rdr.super)
@@ -49,9 +50,10 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
if rdr.super.Magic != magic {
return nil, errNoMagic
}
// if rdr.super.BlockLog == uint16(math.Log2(float64(rdr.super.BlockSize))) {
// return nil, errors.New("BlockSize and BlockLog doesn't match. The archive is probably corrupt")
// }
if rdr.super.BlockLog != uint16(math.Log2(float64(rdr.super.BlockSize))) {
return nil, errors.New("BlockSize and BlockLog doesn't match. The archive is probably corrupt")
}
hasUnsupportedOptions := false
rdr.flags = rdr.super.GetFlags()
if rdr.flags.compressorOptions {
switch rdr.super.CompressionType {
+3 -8
View File
@@ -3,6 +3,7 @@ package squashfs
import (
"fmt"
"io"
"math"
"net/http"
"os"
"os/exec"
@@ -69,19 +70,13 @@ func TestAppImage(t *testing.T) {
}
defer aiFil.Close()
stat, _ := aiFil.Stat()
os.RemoveAll(wd + "/testing/firefox")
ai := goappimage.NewAppImage(wd + "/testing/" + appImageName)
rdr, err := NewSquashfsReader(io.NewSectionReader(aiFil, ai.Offset, stat.Size()-ai.Offset))
if err != nil {
t.Fatal(err)
}
desktop := rdr.GetFileAtPath("*.desktop")
if desktop == nil {
t.Fatal("Problema!")
}
os.Remove(wd + "/testing/cura.desktop")
deskFil, _ := os.Create(wd + "/testing/cura.desktop")
io.Copy(deskFil, desktop.Sys().(io.Reader))
fmt.Println(rdr.super.BlockLog, strconv.FormatInt(int64(rdr.super.BlockSize), 2))
fmt.Println(math.Log2(float64(rdr.super.BlockSize)))
t.Fatal("No problemo!")
}
+4 -3
View File
@@ -13,7 +13,7 @@ import (
"github.com/CalebQ42/squashfs/internal/compression"
)
//Writer is used to creaste squashfs archives. Currently unusable
//Writer is used to creaste squashfs archives. Currently unusable.
//TODO: Make usable
type Writer struct {
compressor compression.Compressor
@@ -21,8 +21,9 @@ type Writer struct {
symlinkTable map[string]string //[oldpath]newpath
uidGUIDTable []int
compressionType int
//BlockSize is how large the data blocks are. Can be between 4096 (4KB) and 1048576 (1 MB). Default is 1048576.
//If BlockSize is not inside that range, it will be set to within the range before writing
//BlockSize is how large the data blocks are. Can be between 4096 (4KB) and 1048576 (1 MB).
//If BlockSize is not inside that range, it will be set to within the range before writing.
//Default is 1048576.
BlockSize uint32
//Flags are the SuperblockFlags used when writing the archive.
//Currently Duplicates, Exportable, UncompressedXattr, NoXattr values are ignored