diff --git a/services/graph/pkg/service/v0/graph_test.go b/services/graph/pkg/service/v0/graph_test.go index 1112dacb2bd..f0c79f9cac9 100644 --- a/services/graph/pkg/service/v0/graph_test.go +++ b/services/graph/pkg/service/v0/graph_test.go @@ -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), diff --git a/services/search/pkg/content/tika_test.go b/services/search/pkg/content/tika_test.go index 8dd2ae5e893..7c4024a9700 100644 --- a/services/search/pkg/content/tika_test.go +++ b/services/search/pkg/content/tika_test.go @@ -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"