瀏覽代碼

Merge pull request #76 from rauls5382/windows_ads

Explicitly return error for empty input files
Hyoun Kyu Cho 8 年之前
父節點
當前提交
4d3aee256f
共有 1 個檔案被更改,包括 10 行新增4 行删除
  1. 10
    4
      profile/profile.go

+ 10
- 4
profile/profile.go 查看文件

155
 			return nil, fmt.Errorf("decompressing profile: %v", err)
155
 			return nil, fmt.Errorf("decompressing profile: %v", err)
156
 		}
156
 		}
157
 	}
157
 	}
158
-	if p, err = ParseUncompressed(data); err != nil {
159
-		if p, err = parseLegacy(data); err != nil {
160
-			return nil, fmt.Errorf("parsing profile: %v", err)
161
-		}
158
+	if p, err = ParseUncompressed(data); err != nil && err != errNoData {
159
+		p, err = parseLegacy(data)
160
+	}
161
+
162
+	if err != nil {
163
+		return nil, fmt.Errorf("parsing profile: %v", err)
162
 	}
164
 	}
163
 
165
 
164
 	if err := p.CheckValid(); err != nil {
166
 	if err := p.CheckValid(); err != nil {
169
 
171
 
170
 var errUnrecognized = fmt.Errorf("unrecognized profile format")
172
 var errUnrecognized = fmt.Errorf("unrecognized profile format")
171
 var errMalformed = fmt.Errorf("malformed profile format")
173
 var errMalformed = fmt.Errorf("malformed profile format")
174
+var errNoData = fmt.Errorf("empty input file")
172
 
175
 
173
 func parseLegacy(data []byte) (*Profile, error) {
176
 func parseLegacy(data []byte) (*Profile, error) {
174
 	parsers := []func([]byte) (*Profile, error){
177
 	parsers := []func([]byte) (*Profile, error){
195
 
198
 
196
 // ParseUncompressed parses an uncompressed protobuf into a profile.
199
 // ParseUncompressed parses an uncompressed protobuf into a profile.
197
 func ParseUncompressed(data []byte) (*Profile, error) {
200
 func ParseUncompressed(data []byte) (*Profile, error) {
201
+	if len(data) == 0 {
202
+		return nil, errNoData
203
+	}
198
 	p := &Profile{}
204
 	p := &Profile{}
199
 	if err := unmarshal(data, p); err != nil {
205
 	if err := unmarshal(data, p); err != nil {
200
 		return nil, err
206
 		return nil, err