Code Monkey home page Code Monkey logo

Comments (3)

danergo avatar danergo commented on August 23, 2024

The problem is that base64_encode put padding in the middle of the stream ('==').

from base64.

aklomp avatar aklomp commented on August 23, 2024

Hey, thanks for the report. I'm a bit baffled by this, because like you say, if the library is run inside a mutex, it should be threadsafe. In fact, it should be fairly threadsafe to start with, because the only shared mutable datastructure it uses is the codec selection structure, which is written to once on the first call. All the other functions are reentrant and do not share common data. So that can't really explain the bug.

The padding is written by base64_stream_encode_final, just before base64_encode returns. So I don't see a way in which it can insert those characters into the middle of a stream. What kind of IO is writeOutput doing? It could be that the IO is not properly flushed between threads, causing the output to be interleaved.

from base64.

danergo avatar danergo commented on August 23, 2024

Before unlocking the mutex, writeOutput adds header and trailer to the base64 data, and sends out through a socket. Now if there were incorrect flushing between threads, it shall be "all-or-nothing" fashion because of the mutex.

I'm not seeing this:
HEADER#(BASE64_1)#TRAILER HEADER#(BASE64_1)(BASE64_2)#TRAILER

But I'm seeing this:
HEADER#(BASE64_1)#TRAILER HEADER#(BASE64_2)(BASE64_3)#TRAILER

This can be easily worked around by splitting the stream at the decoder (or if there is no padding in the middle no need to split at all).

My only concern here is buffer size: I've optimized Base64Buffer to fit 4096 bytes.
Obviously it wont be able handle more data and could cause a segfault.

from base64.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.