You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2019/02/01 10:24:07 UTC
[GitHub] ondra-novak opened a new issue #1895: _bulk_docs/put - damaged _rev
causes uncaught exception
ondra-novak opened a new issue #1895: _bulk_docs/put - damaged _rev causes uncaught exception
URL: https://github.com/apache/couchdb/issues/1895
[NOTE]: # ( ^^ Provide a general summary of the issue in the title above. ^^ )
Putting document with damaged _rev can cause exception returning 500 Internal Error instead of relevant error message
## Description
It is possible to craft _revs by imitating replication and putting documents along with new_edits=false. However, if the _revs looks like revision generated by CouchDB, but it is somehow damaged, the couchdb crashes with exception. This also happens when _bulk_docs is used - rest of the documents are not stored and result of the execution is unknown
[NOTE]: # ( Describe the problem you're encountering. )
[TIP]: # ( Do NOT give us access or passwords to your actual CouchDB! )
## Steps to Reproduce
1. create DB "test"
2.
```
$ curl -iH "Content-Type: application/json" -d '{"docs":[{"_id":"test","aaa":"bbb","_revisions":{"start":1,"ids":["7ea7f65fbd9ddcd547969ca540fed66w"]}},{"_id":"other","_revisions":{"start":1,"ids":["aaa"]}}],"new_edits":false}' "http://localhost:5984/test/_bulk_docs"
```
```
HTTP/1.1 500 Internal Server Error
{"error":"unknown_error","reason":"badarg","ref":1621251896}
```
Notice 'w' in revision of the first document. The second document is not stored.
There is log record:
```
req_err(1621251896) unknown_error : badarg
[<<"erlang:list_to_integer/2">>,<<"couch_doc:parse_revid/1 L165">>,<<"couch_doc:-transfer_fields/3-lc$^2/1-1-/1 L280">>,<<"couch_doc:transfer_fields/3 L280">>,<<"couch_doc:from_json_obj_validate/2 L135">>,<<"chttpd_db:-db_req/2-fun-1-/1 L424">>,<<"lists:map/2 L1239">>,<<"chttpd_db:db_req/2 L423">>]
```
When a crafted _rev is used, the request is executed correctly
```
$ curl -iH "Content-Type: application/json" -d '{"docs":[{"_id":"test","aaa":"bbb","_revisions":{"start":1,"ids":["crafted"]}},{"_id":"other2","_revisions":{"start":1,"ids":["aaa"]}}],"new_edits":false}' "http://localhost:5984/test/_bulk_docs"
```
```
HTTP/1.1 201 Created
[]
```
This bug also appears, when new_edits=false is not used and the revision is damaged.
```
$ curl -X PUT -iH "Content-Type: application/json" -d '{"_id":"test2"}' "http://localhost:5984/test/test2"
```
```
{"ok":true,"id":"test2","rev":"1-967a00dff5e02add41819138abb3284d"}
```
```
$ curl -X PUT -iH "Content-Type: application/json" -d '{"_id":"test2","_rev":"1-967a00dff5e02add41819138abb3284w"}' "http://localhost:5984/test/test2"
```
```
{"error":"unknown_error","reason":"badarg","ref":531824669}
```
However, if the revision is not damaged, just different, correct error message is generated
```
$ curl -X PUT -iH "Content-Type: application/json" -d '{"_id":"test2","_rev":"1-967a00dff5e02add41819138abb32841"}' "http://localhost:5984/test/test2"
```
```
{"error":"conflict","reason":"Document update conflict."}
```
It seems that CouchDB is trying to parse the hash part of the revision when it looks like a valid hash and it fails without handling the exception. The uncaught exception causes error 500
[NOTE]: # ( Include commands to reproduce, if possible. curl is preferred. )
## Expected Behaviour
Uncaught exception should be handled
[NOTE]: # ( Tell us what you expected to happen. )
## Your Environment
[TIP]: # ( Include as many relevant details about your environment as possible. )
[TIP]: # ( You can paste the output of curl http://YOUR-COUCHDB:5984/ here. )
* CouchDB Version used:
{"couchdb":"Welcome","version":"2.3.0","git_sha":"07ea0c7","uuid":"3246e174be789358f6e0855023ea8731","features":["pluggable-storage-engines","scheduler"],"vendor":{"name":"The Apache Software Foundation"}}
* Operating System and version: Ubuntu 18.04
## Additional context
[TIP]: # ( Add any other context about the problem here. )
Not blocking issue, I just found this by mistake during performing tests on my project.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services