Skip to content

Commit 67124a6

Browse files
committed
fix(search): ignore invalid exposure denominators
1 parent db4cee1 commit 67124a6

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎services/search/pkg/content/tika_photo.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ func (t Tika) getPhoto(meta map[string][]string) *libregraph.Photo {
6363
}
6464

6565
if v, err := getFirstValue(meta, "exif:ExposureTime"); err == nil {
66-
if i, err := strconv.ParseFloat(v, 64); err == nil && i > 0 {
67-
initPhoto()
68-
photo.SetExposureNumerator(1)
69-
photo.SetExposureDenominator(math.Round(1 / i))
66+
if i, err := strconv.ParseFloat(v, 64); err == nil {
67+
if d := math.Round(1 / i); !math.IsNaN(d) && !math.IsInf(d, 0) && d > 0 {
68+
initPhoto()
69+
photo.SetExposureNumerator(1)
70+
photo.SetExposureDenominator(d)
71+
}
7072
}
7173
}
7274

‎services/search/pkg/content/tika_test.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,16 @@ var _ = Describe("Tika", func() {
146146
})
147147

148148
It("ignores zero exposure time", func() {
149-
fullResponse = `[{"exif:ExposureTime": "0.0"}]`
149+
fullResponse = `[{"exif:ExposureTime": "0.0", "exif:FNumber": "2.0"}]`
150150

151151
doc, err := tika.Extract(context.TODO(), &provider.ResourceInfo{
152152
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
153153
Size: 1,
154154
})
155155
Expect(err).ToNot(HaveOccurred())
156-
Expect(doc.Photo).To(BeNil())
156+
Expect(doc.Photo).ToNot(BeNil())
157+
Expect(doc.Photo.FNumber).To(Equal(libregraph.PtrFloat64(2)))
158+
Expect(doc.Photo.ExposureDenominator).To(BeNil())
157159
})
158160

159161
It("removes stop words", func() {

0 commit comments

Comments
 (0)