CouchDB
  1. CouchDB
  2. COUCHDB-1022

Doc GET multipart/related and multipart/mixed APIs with wrong lengths in attachment stubs

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.11, 0.11.1, 0.11.2, 1.0, 1.0.1
    • Fix Version/s: 1.0.2, 1.0.3, 1.1
    • Labels:
      None
    • Environment:

      all

      Description

      Up to 1.0.1, it was possible to loose the identity length of an attachment that was compressed by CouchDB. The only case known where this happened was after doing a local to local replication. This was found and fixed recently in 1.0.x with a patch from Juuso Väänänen, COUCHDB-930.

      However, existing databases created with versions up to 1.0.1, have the attachment identify length lost forever. For this cases, the multipart/related or multipart/mixed APIs used to GET a document, return attachments stubs with a "length" field matching the length of the attachment in compressed form, and the part of the multipart stream that contains the attachment, contains it in uncompressed form.

      This poses a serious problem to the CouchDB multipart parser, an essential part used by the new replicator that's likely to land on the 1.2 release. Without this fix, it may not be possible to do pull replications, with the new replicator, from versions 0.11.0, 0.11.1, 0.11.2, 1.0.0 and 1.0.1 ONLY when the source database was the product of a local to local replication (and there are attachments stored in compressed form, as described by COUCHDB-930).

      The following patch fixes this issue by always sending the attachments in compressed form. It's meant to be applied against branches 0.11.x, 1.0.x, 1.1.x and trunk.

        Activity

        Hide
        Filipe Manana added a comment -

        Patch applied to all the branches mentioned in the description.

        Show
        Filipe Manana added a comment - Patch applied to all the branches mentioned in the description.
        Hide
        Robert Newson added a comment - - edited

        I added a guard clause to write_streamed_attachment so we blow up earlier. This seemed simpler than adding a clause that just throws, which felt quite unidiomatic. The main clause is now explicit about its expectation of positive valence on LenLeft.

        -write_streamed_attachment(Stream, F, LenLeft) ->
        +write_streamed_attachment(Stream, F, LenLeft) when LenLeft > 0 ->

        Sadly I referenced COUCHDB-1021 and not 1022 in the commit msg

        Show
        Robert Newson added a comment - - edited I added a guard clause to write_streamed_attachment so we blow up earlier. This seemed simpler than adding a clause that just throws, which felt quite unidiomatic. The main clause is now explicit about its expectation of positive valence on LenLeft. -write_streamed_attachment(Stream, F, LenLeft) -> +write_streamed_attachment(Stream, F, LenLeft) when LenLeft > 0 -> Sadly I referenced COUCHDB-1021 and not 1022 in the commit msg
        Hide
        Filipe Manana added a comment -

        Robert, perfectly fine, simpler than explicitly throwing an exception when LenLeft < 0.
        thanks

        Show
        Filipe Manana added a comment - Robert, perfectly fine, simpler than explicitly throwing an exception when LenLeft < 0. thanks

          People

          • Assignee:
            Filipe Manana
            Reporter:
            Filipe Manana
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development