Compare commits

...
Author SHA1 Message Date
Michal Klos 23d6de0e45 fix: [se-807] space image regression tests 2026-09-16 22:44:49 +02:00
Michal Klos b57799ad0a fix: [se-807] space image regression tests 2026-09-16 18:43:07 +02:00
3 changed files with 147 additions and 1 deletions

No files matched your search

+8 -1
View File
@@ -41,6 +41,10 @@ def parse_json_stream(path):
objects.append(obj)
return objects
ACKNOWLEDGED = {
"GO-2026-6443",
}
objects = parse_json_stream(sys.argv[1])
# Collect OSV details
@@ -73,7 +77,9 @@ for vid, entries in sorted(by_vuln.items()):
module = trace[0].get('module', '') if trace else ''
# Determine category
if not is_called:
if vid in ACKNOWLEDGED:
category = "ACKNOWLEDGED"
elif not is_called:
category = "IMPORTED"
elif not fixed_version:
category = "NO_FIX"
@@ -106,6 +112,7 @@ if warn_vulns:
'NO_FIX': 'no upstream fix available',
'STDLIB': f'needs Go toolchain upgrade to {v["fixed_version"]}',
'IMPORTED': 'code does not call vulnerable function',
'ACKNOWLEDGED': f'explicitly acknowledged, fix pending (bump to {v["fixed_version"]})',
}.get(v['category'], v['category'])
print(f" {v['id']}: {v['summary']}")
print(f" module={v['module']} ({reason})")
@@ -192,6 +192,70 @@ var _ = Describe("Graph", func() {
}
`))
})
// Regression test for SE-807 (FAILS until fixed): a project space whose space-image
// node carries a non-finite float in its ArbitraryMetadata (e.g.
// photo.exposureDenominator="+Inf", written back by the search/Tika extractor) must
// not blow up the whole drive listing. strconv.ParseFloat accepts "+Inf"/"NaN"
// (driveitems.go unmarshalStringMap), encoding/json then cannot marshal the value,
// and render.JSON silently replies 500 with no body/log. Expected: 200 with the
// drive listed and the non-finite facet dropped.
It("lists a space whose image node has a non-finite float facet without 500ing", func() {
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Times(1).Return(&provider.ListStorageSpacesResponse{
Status: status.NewOK(ctx),
StorageSpaces: []*provider.StorageSpace{
{
Id: &provider.StorageSpaceId{OpaqueId: "sameID"},
SpaceType: "project",
Root: &provider.ResourceId{
StorageId: "pro-1",
SpaceId: "sameID",
OpaqueId: "sameID",
},
Name: "aspacename",
Opaque: utils.AppendPlainToOpaque(nil, "image", "pro-1$sameID!imageNode"),
},
},
}, nil)
gatewayClient.On("GetQuota", mock.Anything, mock.Anything).Return(&provider.GetQuotaResponse{
Status: status.NewUnimplemented(ctx, fmt.Errorf("not supported"), "not supported"),
}, nil)
gatewayClient.On("GetPath", mock.Anything, mock.Anything).Return(&provider.GetPathResponse{
Status: status.NewOK(ctx),
Path: "/.space/image.png",
}, nil)
// Stat on the space-image node returns a corrupt (non-finite) photo facet.
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(&provider.StatResponse{
Status: status.NewOK(ctx),
Info: &provider.ResourceInfo{
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Id: &provider.ResourceId{StorageId: "pro-1", SpaceId: "sameID", OpaqueId: "imageNode"},
MimeType: "image/jpeg",
ArbitraryMetadata: &provider.ArbitraryMetadata{
Metadata: map[string]string{
"libre.graph.photo.exposureDenominator": "+Inf",
},
},
},
}, nil)
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me/drives", nil)
r = r.WithContext(ctx)
rr := httptest.NewRecorder()
svc.GetDrivesV1Beta1(rr, r)
Expect(rr.Code).To(Equal(http.StatusOK))
body, _ := io.ReadAll(rr.Body)
var response map[string][]libregraph.Drive
Expect(json.Unmarshal(body, &response)).To(Succeed())
Expect(len(response["value"])).To(Equal(1))
// the non-finite facet value must be dropped, not surfaced
for _, item := range response["value"][0].Special {
if item.Photo != nil {
Expect(item.Photo.ExposureDenominator).To(BeNil())
}
}
})
It("can list a spaces with sort", func() {
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(&provider.ListStorageSpacesResponse{
Status: status.NewOK(ctx),
+75
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"math"
"net/http"
"net/http/httptest"
"strings"
@@ -216,6 +217,80 @@ var _ = Describe("Tika", func() {
Expect(photo.TakenDateTime).To(Equal(libregraph.PtrTime(time.Date(2018, 1, 1, 12, 34, 56, 0, time.UTC))))
})
// Root-cause regression test for SE-807 (FAILS until fixed): an EXIF ExposureTime of
// "0" makes getPhoto compute math.Round(1/0) = +Inf for the exposure denominator.
// That non-finite value is later persisted (as the string "+Inf") and read back into
// a drive facet, where it breaks JSON encoding of the whole drive listing. The
// extractor must not emit a non-finite denominator for a zero exposure time.
It("does not emit a non-finite exposure denominator for a zero exposure time", func() {
fullResponse = `[
{
"tiff:Make": "Canon",
"exif:ExposureTime": "0"
}
]`
doc, err := tika.Extract(context.TODO(), &provider.ResourceInfo{
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Size: 1,
})
Expect(err).ToNot(HaveOccurred())
Expect(doc.Photo).ToNot(BeNil())
if doc.Photo.ExposureDenominator != nil {
Expect(math.IsInf(*doc.Photo.ExposureDenominator, 0)).To(BeFalse())
Expect(math.IsNaN(*doc.Photo.ExposureDenominator)).To(BeFalse())
}
})
It("falls back to Base ISO when exif:IsoSpeedRatings is absent", func() {
fullResponse = `[
{
"tiff:Make": "Canon",
"Base ISO": "200"
}
]`
doc, err := tika.Extract(context.TODO(), &provider.ResourceInfo{
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Size: 1,
})
Expect(err).ToNot(HaveOccurred())
Expect(doc.Photo).ToNot(BeNil())
Expect(doc.Photo.Iso).To(Equal(libregraph.PtrInt32(200)))
})
It("extracts metadata from oversized files using truncated stream", func() {
fullResponse = `[
{
"tiff:Make": "Google",
"tiff:Model": "Pixel 7",
"exif:FNumber": "1.85",
"exif:FocalLength": "6.81",
"Base ISO": "58",
"tiff:Orientation": "1",
"exif:DateTimeOriginal": "2024-06-15T14:30:00",
"tiff:ImageWidth": "4080",
"tiff:ImageLength": "3072"
}
]`
tika.ContentExtractionSizeLimit = 10
doc, err := tika.Extract(context.TODO(), &provider.ResourceInfo{
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Size: 8_000_000,
})
Expect(err).ToNot(HaveOccurred())
Expect(doc.Photo).ToNot(BeNil())
Expect(doc.Photo.CameraMake).To(Equal(libregraph.PtrString("Google")))
Expect(doc.Photo.CameraModel).To(Equal(libregraph.PtrString("Pixel 7")))
Expect(doc.Photo.TakenDateTime).ToNot(BeNil())
Expect(doc.Image).ToNot(BeNil())
Expect(doc.Image.Width).To(Equal(libregraph.PtrInt32(4080)))
Expect(doc.Image.Height).To(Equal(libregraph.PtrInt32(3072)))
})
It("removes stop words", func() {
body = "body to test stop words!!! against almost everyone"
language = "en"