Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing an open list and then a footer causes an off by one error #5

Closed
spinningtopsofdoom opened this issue Jul 11, 2014 · 3 comments

Comments

@spinningtopsofdoom
Copy link

If you write an open list, end it, and then write a footer the validation logic for the number of bytes fails. The length reported in the footer and the calculated length are off by one. Here is a example that produces the error

(require '[clojure.data.fressian :as fress])
(import '[org.fressian.impl ByteBufferInputStream BytesOutputStream InheritanceLookup])
(let [my-os (BytesOutputStream.)
      fw (fress/create-writer my-os) ]
  (do
   (fress/begin-open-list fw)
   (fress/end-list fw)
   (fress/write-footer fw)
   (fress/write-object fw nil)
   (let [ my-is (fress/to-input-stream (.internalBuffer my-os))
         fr (fress/create-reader my-is)]
     [(fress/read-object fr) (fress/read-object fr)])))

I believe the cause is in the beginOpenList method of FressianWriter

public Writer beginOpenList() throws IOException {
        if (0 != rawOut.getBytesWritten())
            throw new IllegalStateException("openList must be called from the top level, outside any footer context.");
        writeCode(Codes.BEGIN_OPEN_LIST);
        rawOut.reset();
        return this;
    }

The byte code for the open list is written, then the stream is reset making the reported number of bytes written zero, not one.

@rschmitt
Copy link

Speaking as a member of the peanut gallery, this is an outstanding bug report and I'm surprised that you haven't gotten any kind of response.

@stuarthalloway
Copy link
Contributor

Considering 07f9443 as a fix for this.

@puredanger
Copy link
Contributor

Fixed in 0.6.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants