|
@@ -155,10 +155,12 @@ func ParseData(data []byte) (*Profile, error) {
|
155
|
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
|
166
|
if err := p.CheckValid(); err != nil {
|
|
@@ -169,6 +171,7 @@ func ParseData(data []byte) (*Profile, error) {
|
169
|
171
|
|
170
|
172
|
var errUnrecognized = fmt.Errorf("unrecognized profile format")
|
171
|
173
|
var errMalformed = fmt.Errorf("malformed profile format")
|
|
174
|
+var errNoData = fmt.Errorf("empty input file")
|
172
|
175
|
|
173
|
176
|
func parseLegacy(data []byte) (*Profile, error) {
|
174
|
177
|
parsers := []func([]byte) (*Profile, error){
|
|
@@ -195,6 +198,9 @@ func parseLegacy(data []byte) (*Profile, error) {
|
195
|
198
|
|
196
|
199
|
// ParseUncompressed parses an uncompressed protobuf into a profile.
|
197
|
200
|
func ParseUncompressed(data []byte) (*Profile, error) {
|
|
201
|
+ if len(data) == 0 {
|
|
202
|
+ return nil, errNoData
|
|
203
|
+ }
|
198
|
204
|
p := &Profile{}
|
199
|
205
|
if err := unmarshal(data, p); err != nil {
|
200
|
206
|
return nil, err
|