Skip to content

Commit a8ac1f7

Browse files
andrewkrohmergify-bot
authored andcommitted
Improve aws-s3 gzip file detection to avoid false negatives (#29969)
Directly check the byte stream for the gzip magic number and deflate compression type. Avoid using http.DetectContentType because it returns the first match it finds while checking many signatures. Closes #29968 (cherry picked from commit 61a7d36)
1 parent cd16c9f commit a8ac1f7

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

CHANGELOG.next.asciidoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
5353
*Filebeat*
5454

5555
- aws-s3: Stop trying to increase SQS message visibility after ReceiptHandleIsInvalid errors. {pull}29480[29480]
56+
- Fix handling of IPv6 addresses in netflow flow events. {issue}19210[19210] {pull}29383[29383]
57+
- Fix `sophos` KV splitting and syslog header handling {issue}24237[24237] {pull}29331[29331]
58+
- Undo deletion of endpoint config from cloudtrail fileset in {pull}29415[29415]. {pull}29450[29450]
59+
- Make Cisco ASA and FTD modules conform to the ECS definition for event.outcome and event.type. {issue}29581[29581] {pull}29698[29698]
60+
- ibmmq: Fixed `@timestamp` not being populated with correct values. {pull}29773[29773]
61+
- aws-s3: Improve gzip detection to avoid false negatives. {issue}29968[29968]
5662

5763
*Heartbeat*
5864

x-pack/filebeat/input/awss3/s3_objects.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"fmt"
1616
"io"
1717
"io/ioutil"
18-
"net/http"
1918
"reflect"
2019
"strings"
2120
"time"
@@ -375,18 +374,13 @@ func s3ObjectHash(obj s3EventV2) string {
375374
// stream without consuming it. This makes it convenient for code executed after this function call
376375
// to consume the stream if it wants.
377376
func isStreamGzipped(r *bufio.Reader) (bool, error) {
378-
// Why 512? See https://godoc.org/net/http#DetectContentType
379-
buf, err := r.Peek(512)
377+
buf, err := r.Peek(3)
380378
if err != nil && err != io.EOF {
381379
return false, err
382380
}
383381

384-
switch http.DetectContentType(buf) {
385-
case "application/x-gzip", "application/zip":
386-
return true, nil
387-
default:
388-
return false, nil
389-
}
382+
// gzip magic number (1f 8b) and the compression method (08 for DEFLATE).
383+
return bytes.HasPrefix(buf, []byte{0x1F, 0x8B, 0x08}), nil
390384
}
391385

392386
// s3Metadata returns a map containing the selected S3 object metadata keys.

0 commit comments

Comments
 (0)