nickva commented on a change in pull request #817: Don't crash on invalid
inline attachments
URL: https://github.com/apache/couchdb/pull/817#discussion_r138924705
##########
File path: src/couch/src/couch_att.erl
##########
@@ -412,13 +412,21 @@ follow_from_json(Att, Props) ->
inline_from_json(Att, Props) ->
B64Data = couch_util:get_value(<<"data">>, Props),
- Data = base64:decode(B64Data),
- Length = size(Data),
- RevPos = couch_util:get_value(<<"revpos">>, Props, 0),
- store([
- {data, Data}, {revpos, RevPos}, {disk_len, Length},
- {att_len, Length}
- ], Att).
+ try base64:decode(B64Data) of
+ Data ->
+ Length = size(Data),
+ RevPos = couch_util:get_value(<<"revpos">>, Props, 0),
+ store([
+ {data, Data}, {revpos, RevPos}, {disk_len, Length},
+ {att_len, Length}
+ ], Att)
+ catch
+ _:_ ->
Review comment:
Wonder if we should be more conservative and explicitly match on the knows
exception tags and error message
```
error:function_clause
error:{badmatch, _}
```
the `function_clause` happens when is an invalid input data type such as
undefined or list.
`badmatch` happens if type is correct but data is not a valid B64 encoding.
But I guess it's not clear that there couldn't be other errors thrown so
maybe catching all is ok there. Docs don't say what exactly should be thrown.
So up to you here. I am 50/50 on this one.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services