A SIXEL encoder/decoder implementation derived from kmiya's sixel

Overview

libsixel

Build Status Coverage Status

What is this?

This package provides encoder/decoder implementation for DEC SIXEL graphics, and some converter programs.

img2sixel(https://youtu.be/0SasrQ7pnbA)

SIXEL is one of image formats for printer and terminal imaging introduced by Digital Equipment Corp. (DEC). Its data scheme is represented as a terminal-friendly escape sequence. So if you want to view a SIXEL image file, all you have to do is "cat" it to your terminal.

On 80's real hardware terminals, it tooks unbearable long waiting times to display images.

vt330sixel

But nowdays, with high-speed CPU and broadband network, we got the chance to develop a new scope of SIXELs.

SIXEL Animation

img2sixel(1) can decode GIF animation.

Animation

Related projects

Video streaming

Now Youtube video streaming is available over SIXEL protocol by FFmpeg-SIXEL project.

FFmpeg-SIXEL

Above demo only uses 16 color registers.

SDL integration: Gaming, Virtualization, ...etc.

SDL1.2-SIXEL project makes enable you to operate various GUI applications on the terminal.

You can play "The Battle for Wesnoth" over SIXEL protocol.

SDL1.2-SIXEL WESNOTH

You can run QEMU on SIXEL terminals.

SDL1.2-SIXEL QEMU

SDL1.2-SIXEL can collaborate with XSDL-SIXEL.

SDL1.2-SIXEL XSDL

Furthermore some information of SIXEL-ready SDL applications are reported.

Langage Bindings

libsixel-python

converter.py example depends on it.

mruby-sixel

Used by mruby-webcam.

libsixel-p6

A perl6 bindings for libsixel

sixel-sys

Rust FFI bindings for libsixel

sixel-rs

A safe Rust wrapper for libsixel

W3M integration

img2sixel(1) can be integrated with Debian's w3m(maintained by Tatsuya Kinoshita) that includes patches for -sixel option derived from Arakiken's w3m fork(remoteimg branch).

w3m-sixel

@uobikiemukot's sdump project selected another approach. He wrote a w3mimgdisplay compatible program yaimg-sixel. It also works with ranger.

w3m-yaimg-sixel

X11 on SIXEL terminals

Xsixel is a kdrive server implementation for SIXEL terminals.

Xsixel

Xsixel Blue Print

GNU Screen integration

Arakiken's GNU Screen fork(sixel branch) works with SIXEL-supported applications including above products. This project is now in progress. GUI flavored SIXEL applications will integrated with existing terminal applications on it.

w3m-sixel-screen

sixel-screen

xsixel-screen

See also on youtube.

Twitter client integration

Some NetBSD/OpenBSD users are doing amazing challenges.

arakiken's mikutterm(mikutterm-sixel)

Now mikutter + mikutterm works with libsixel inline-image extension.

SIXEL works with old powerless machines such as

NetBSD/luna68k (here is OMRON LUNA-II):

mikutterm-netbsd-luna68k

NetBSD/hp300 (here is HP9000/425e):

mikutterm-netbsd-hp9000

arakiken's tw(tw-sixel)

arakiken's tw(tw-sixel) works with libsixel inline-image extension.

SIXEL works with old powerless machines such as OpenBSD/luna88k (here is OMRON LUNA-88K2 MC88100@33MHz):

mikutterm-netbsd-hp9000

sayaka-chan

sayaka-chan(PHP version) works with libsixel inline-image extension.

SIXEL works with old powerless machines such as NetBSD/x68k (here is SHARP X68030 with 060turbo):

sayaka-chan

SIXEL works even in-kernel console. @isaki68k wrote a patch for ite(4).

ite(4)

Other

sixelSPAD

screenshot

Includes 2 commands fricas2sixel and latex2sixel.

latex2sixel

Neofetch

Now sixel backend is implemented. See https://github.com/dylanaraps/neofetch/wiki/Image-Backends#sixel

neofetch

termplay

Depends on sixel-sys, --converter=sixel option is supported.

termplay

sixelPreviewer

Simple scripts and development environment for realtime edit-previewing for dot, svg, markdown, ...etc. sixelPreviewer

sdump

A sixel image dumper, provides pdf previewer.

RetroArch

SIXEL video driver is provided if you build it with --enable-sixel option. (screenshot)

Highlighted features

Improved compression

Former sixel encoders(such as ppmtosixel) are mainly designed for dot-matrix printers. They minimize the amount of printer-head movement distance. But nowadays this method did not represent the best performance for displaying sixel data on terminal emulators. SIXEL data for terminals were found in 80's Usenet, but the technology of how to create them seems to be lost. kmiya's sixel introduces the encoding method which is re-designed for terminal emulators to optimize the overhead of transporting SIXEL with keeping compatibility with former SIXEL terminal. Now libsixel and ImageMagick's sixel coder follow it.

@arakiken, known as the maintainer of mlterm, describes about the way to generate high quality SIXEL, which is adopted by libsixel (http://mlterm.sourceforge.net/libsixel.pdf, in Japanese).

High quality quantization

img2sixel(1) supports color image quantization. It works well even if few number of colors are allowed.

Terminal requirements

If you want to view a SIXEL image, you have to get a terminal which support sixel graphics.

Now SIXEL feature is supported by the following terminals.

  • DEC VT series, VT240/VT241/VT330/VT340/VT282/VT284/VT286/VT382

  • DECterm(dxterm)

  • Kermit

  • ZSTEM 340

  • WRQ Reflection

  • RLogin (Japanese terminal emulator)

    http://nanno.dip.jp/softlib/man/rlogin/

  • mlterm

    http://mlterm.sourceforge.net/

    Works on each of X, WIN32 GDI, framebuffer, Android, Cocoa version.

  • XTerm (compiled with --enable-sixel-graphics option)

    http://invisible-island.net/xterm/

    You should launch xterm with "-ti vt340" option. The SIXEL palette is limited to a maximum of 16 colors. To avoid this limitation, Try

> $HOME/.Xresources $ echo "XTerm*numColorRegisters: 256" >> $HOME/.Xresources $ xrdb $HOME/.Xresources $ xterm ">
$ echo "XTerm*decTerminalID: vt340" >> $HOME/.Xresources
$ echo "XTerm*numColorRegisters: 256" >>  $HOME/.Xresources
$ xrdb $HOME/.Xresources
$ xterm

or

$ xterm -xrm "XTerm*decTerminalID: vt340" -xrm "XTerm*numColorRegisters: 256"

Install

Using package managers

You can install libsixel via the following package systems.

Build from source package

$ ./configure
$ make
# make install

Build with optional packages

You can configure with the following options

--with-libcurl            build with libcurl (default: auto)
--with-gd                 build with libgd (default: no)
--with-gdk-pixbuf2        build with gdk-pixbuf2 (default: no)
--with-jpeg               build with libjpeg (default: auto)
--with-png                build with libpng (default: auto)
--with-pkgconfigdir       specify pkgconfig dir (default is libdir/pkgconfig)
--with-bashcompletiondir  specify bashcompletion.d
--with-zshcompletiondir   specify zshcompletion.d
--enable-python           Python interface (default: yes)
--enable-debug            Use debug macro and specific CFLAGS
--enable-gcov             Use gcov
--enable-tests            Build tests

For more information, see "./configure --help".

Cross compiling with MinGW

You can build a windows binary in cross-build environment.

$ CC=i686-w64-mingw32-gcc cross_compile=yes ./configure --host=i686-w64-mingw32
$ make

Usage of command line tools

img2sixel

Usage: img2sixel [Options] imagefiles
       img2sixel [Options] < imagefile

Options:
-o, --outfile              specify output file name.
                           (default:stdout)
-7, --7bit-mode            generate a sixel image for 7bit
                           terminals or printers (default)
-8, --8bit-mode            generate a sixel image for 8bit
                           terminals or printers
-R, --gri-limit            limit arguments of DECGRI('!') to 255
-p COLORS, --colors=COLORS specify number of colors to reduce
                           the image to (default=256)
-m FILE, --mapfile=FILE    transform image colors to match this
                           set of colorsspecify map
-e, --monochrome           output monochrome sixel image
                           this option assumes the terminal
                           background color is black
-k, --insecure             allow to connect to SSL sites without
                           certs(enabled only when configured
                           with --with-libcurl)
-i, --invert               assume the terminal background color
                           is white, make sense only when -e
                           option is given
-I, --high-color           output 15bpp sixel image
-u, --use-macro            use DECDMAC and DEVINVM sequences to
                           optimize GIF animation rendering
-n MACRONO, --macro-number=MACRONO
                           specify an number argument for
                           DECDMAC and make terminal memorize
                           SIXEL image. No image is shown if
                           this option is specified
-C COMPLEXIONSCORE, --complexion-score=COMPLEXIONSCORE
                           specify an number argument for the
                           score of complexion correction.
                           COMPLEXIONSCORE must be 1 or more.
-g, --ignore-delay         render GIF animation without delay
-S, --static               render animated GIF as a static image
-d DIFFUSIONTYPE, --diffusion=DIFFUSIONTYPE
                           choose diffusion method which used
                           with -p option (color reduction)
                           DIFFUSIONTYPE is one of them:
                             auto     -> choose diffusion type
                                         automatically (default)
                             none     -> do not diffuse
                             fs       -> Floyd-Steinberg method
                             atkinson -> Bill Atkinson's method
                             jajuni   -> Jarvis, Judice & Ninke
                             stucki   -> Stucki's method
                             burkes   -> Burkes' method
                             a_dither -> positionally stable
                                         arithmetic dither
                             x_dither -> positionally stable
                                         arithmetic xor based dither
-f FINDTYPE, --find-largest=FINDTYPE
                           choose method for finding the largest
                           dimension of median cut boxes for
                           splitting, make sense only when -p
                           option (color reduction) is
                           specified
                           FINDTYPE is one of them:
                             auto -> choose finding method
                                     automatically (default)
                             norm -> simply comparing the
                                     range in RGB space
                             lum  -> transforming into
                                     luminosities before the
                                     comparison
-s SELECTTYPE, --select-color=SELECTTYPE
                           choose the method for selecting
                           representative color from each
                           median-cut box, make sense only
                           when -p option (color reduction) is
                           specified
                           SELECTTYPE is one of them:
                             auto      -> choose selecting
                                          method automatically
                                          (default)
                             center    -> choose the center of
                                          the box
                             average    -> calculate the color
                                          average into the box
                             histogram -> similar with average
                                          but considers color
                                          histogram
-c REGION, --crop=REGION   crop source image to fit the
                           specified geometry. REGION should
                           be formatted as '%dx%d+%d+%d'
-w WIDTH, --width=WIDTH    resize image to specified width
                           WIDTH is represented by the
                           following syntax
                             auto       -> preserving aspect
                                           ratio (default)
                             
   
    %  -> scale width with
                                           given percentage
                             
    
        -> scale width with
                                           pixel counts
                             
     
      px -> scale width with
                                           pixel counts
-h HEIGHT, --height=HEIGHT resize image to specified height
                           HEIGHT is represented by the
                           following syntax
                             auto       -> preserving aspect
                                           ratio (default)
                             
      
       %  -> scale height with
                                           given percentage
                             
       
         -> scale height with pixel counts 
        
         px -> scale height with pixel counts -r RESAMPLINGTYPE, --resampling=RESAMPLINGTYPE choose resampling filter used with -w or -h option (scaling) RESAMPLINGTYPE is one of them: nearest -> Nearest-Neighbor method gaussian -> Gaussian filter hanning -> Hanning filter hamming -> Hamming filter bilinear -> Bilinear filter (default) welsh -> Welsh filter bicubic -> Bicubic filter lanczos2 -> Lanczos-2 filter lanczos3 -> Lanczos-3 filter lanczos4 -> Lanczos-4 filter -q QUALITYMODE, --quality=QUALITYMODE select quality of color quanlization. auto -> decide quality mode automatically (default) low -> low quality and high speed mode high -> high quality and low speed mode full -> full quality and careful speed mode -l LOOPMODE, --loop-control=LOOPMODE select loop control mode for GIF animation. auto -> honor the setting of GIF header (default) force -> always enable loop disable -> always disable loop -t PALETTETYPE, --palette-type=PALETTETYPE select palette color space type auto -> choose palette type automatically (default) hls -> use HLS color space rgb -> use RGB color space -b BUILTINPALETTE, --builtin-palette=BUILTINPALETTE select built-in palette type xterm16 -> X default 16 color map xterm256 -> X default 256 color map vt340mono -> VT340 monochrome map vt340color -> VT340 color map gray1 -> 1bit grayscale map gray2 -> 2bit grayscale map gray4 -> 4bit grayscale map gray8 -> 8bit grayscale map -E ENCODEPOLICY, --encode-policy=ENCODEPOLICY select encoding policy auto -> choose encoding policy automatically (default) fast -> encode as fast as possible size -> encode to as small sixel sequence as possible -B BGCOLOR, --bgcolor=BGCOLOR specify background color BGCOLOR is represented by the following syntax #rgb #rrggbb #rrrgggbbb #rrrrggggbbbb rgb:r/g/b rgb:rr/gg/bb rgb:rrr/ggg/bbb rgb:rrrr/gggg/bbbb -P, --penetrate penetrate GNU Screen using DCS pass-through sequence -D, --pipe-mode [[deprecated]] read source images from stdin continuously -v, --verbose show debugging info -V, --version show version and license info -H, --help show this help Environment variables: SIXEL_BGCOLOR specify background color. overrided by -B(--bgcolor) option. represented by the following syntax: #rgb #rrggbb #rrrgggbbb #rrrrggggbbbb rgb:r/g/b rgb:rr/gg/bb rgb:rrr/ggg/bbb rgb:rrrr/gggg/bbbb 
        
       
      
     
    
   

Convert a jpeg image file into a sixel file

$ img2sixel < images/egret.jpg > egret.sixel

Reduce colors to 16:

$ img2sixel -p 16 < images/egret.jpg > egret.sixel

Reduce colors with fixed palette:

$ img2sixel -m images/map16.png < images/egret.jpg > egret.sixel

sixel2png

Usage: sixel2png -i input.sixel -o output.png
       sixel2png < input.sixel > output.png

Options:
-i, --input     specify input file
-o, --output    specify output file
-V, --version   show version and license information
-H, --help      show this help

Convert a sixel file into a png image file

$ sixel2png < egret.sixel > egret.png

The high-level conversion API

The high-livel API provides File-to-File conversion features.

Encoder

The sixel encoder object and related functions provides almost same features as img2sixel.

/* create encoder object */
SIXELAPI SIXELSTATUS
sixel_encoder_new(
    sixel_encoder_t     /* out */ **ppencoder, /* encoder object to be created */
    sixel_allocator_t   /* in */  *allocator); /* allocator, null if you use
                                                  default allocator */

/* increase reference count of encoder object (thread-unsafe) */
SIXELAPI void
sixel_encoder_ref(sixel_encoder_t /* in */ *encoder);

/* decrease reference count of encoder object (thread-unsafe) */
SIXELAPI void
sixel_encoder_unref(sixel_encoder_t /* in */ *encoder);

/* set cancel state flag to encoder object */
SIXELAPI SIXELSTATUS
sixel_encoder_set_cancel_flag(
    sixel_encoder_t /* in */ *encoder,
    int             /* in */ *cancel_flag);

/* set an option flag to encoder object */
SIXELAPI SIXELSTATUS
sixel_encoder_setopt(
    sixel_encoder_t /* in */ *encoder,
    int             /* in */ arg,
    char const      /* in */ *optarg);

/* load source data from specified file and encode it to SIXEL format */
SIXELAPI SIXELSTATUS
sixel_encoder_encode(
    sixel_encoder_t /* in */ *encoder,
    char const      /* in */ *filename);

Decoder

The sixel decoder object and related functions provides almost same features as sixel2png.

/* create decoder object */
SIXELAPI SIXELSTATUS
sixel_decoder_new(
    sixel_decoder_t    /* out */ **ppdecoder,  /* decoder object to be created */
    sixel_allocator_t  /* in */  *allocator);  /* allocator, null if you use
                                                  default allocator */

/* increase reference count of decoder object (thread-unsafe) */
SIXELAPI void
sixel_decoder_ref(sixel_decoder_t *decoder);

/* decrease reference count of decoder object (thread-unsafe) */
SIXELAPI void
sixel_decoder_unref(sixel_decoder_t *decoder);

/* set an option flag to decoder object */
SIXELAPI SIXELSTATUS
sixel_decoder_setopt(
    sixel_decoder_t /* in */ *decoder,  /* decoder object */
    int             /* in */ arg,       /* one of SIXEL_OPTFLAG_*** */
    char const      /* in */ *optarg);  /* null or an argument of optflag */

/* load source data from stdin or the file specified with
   SIXEL_OPTFLAG_INPUT flag, and decode it */
SIXELAPI SIXELSTATUS
sixel_decoder_decode(
    sixel_decoder_t /* in */ *decoder);

The low-level conversion API

The low-livel API provides Bytes-to-Bytes conversion features.

The Whole API is described here.

Examples

OpenGL

OpenGL example suggests how to port your OpenGL application to SIXEL terminal.

opengl example

Drawing

Drawing example suggests how to implement the interaction among SIXEL terminals and pointer devices.

drawing

Python

Python example suggests how to convert PIL images into SIXEL using libsixel python interface.

Bitmap to SIXEL

sixel_encode function converts bitmap array into SIXEL format.

/* convert pixels into sixel format and write it to output context */
SIXELAPI SIXELSTATUS
sixel_encode(
    unsigned char  /* in */ *pixels,     /* pixel bytes */
    int            /* in */  width,      /* image width */
    int            /* in */  height,     /* image height */
    int            /* in */  depth,      /* color depth: now unused */
    sixel_dither_t /* in */ *dither,     /* dither context */
    sixel_output_t /* in */ *context);   /* output context */

To use this function, you have to initialize two objects,

  • sixel_dither_t (dithering context object)
  • sixel_output_t (output context object)

Dithering context

Here is a part of APIs for dithering context manipulation.

/* create dither context object */
SIXELAPI SIXELSTATUS
sixel_dither_new(
    sixel_dither_t      /* out */   **ppdither,  /* dither object to be created */
    int                 /* in */    ncolors,     /* required colors */
    sixel_allocator_t   /* in */    *allocator); /* allocator, null if you use
                                                    default allocator */

/* get built-in dither context object */
SIXELAPI sixel_dither_t *
sixel_dither_get(int builtin_dither); /* ID of built-in dither object */

/* destroy dither context object */
SIXELAPI void
sixel_dither_destroy(sixel_dither_t *dither); /* dither context object */

/* increase reference count of dither context object (thread-unsafe) */
SIXELAPI void
sixel_dither_ref(sixel_dither_t *dither); /* dither context object */

/* decrease reference count of dither context object (thread-unsafe) */
SIXELAPI void
sixel_dither_unref(sixel_dither_t *dither); /* dither context object */

/* initialize internal palette from specified pixel buffer */
SIXELAPI SIXELSTATUS
sixel_dither_initialize(
    sixel_dither_t *dither,          /* dither context object */
    unsigned char /* in */ *data,    /* sample image */
    int /* in */ width,              /* image width */
    int /* in */ height,             /* image height */
    int /* in */ pixelformat,        /* one of enum pixelFormat */
    int /* in */ method_for_largest, /* method for finding the largest dimension */
    int /* in */ method_for_rep,     /* method for choosing a color from the box */
    int /* in */ quality_mode);      /* quality of histogram processing */

/* set diffusion type, choose from enum methodForDiffuse */
SIXELAPI void
sixel_dither_set_diffusion_type(
    sixel_dither_t /* in */ *dither,   /* dither context object */
    int /* in */ method_for_diffuse);  /* one of enum methodForDiffuse */

/* get number of palette colors */
SIXELAPI int
sixel_dither_get_num_of_palette_colors(
    sixel_dither_t /* in */ *dither);  /* dither context object */

/* get number of histogram colors */
SIXELAPI int
sixel_dither_get_num_of_histogram_colors(
    sixel_dither_t /* in */ *dither);  /* dither context object */

/* get palette */
SIXELAPI unsigned char *
sixel_dither_get_palette(
    sixel_dither_t /* in */ *dither);  /* dither context object */

/* set palette */
SIXELAPI void
sixel_dither_set_palette(
    sixel_dither_t /* in */ *dither,   /* dither context object */
    unsigned char  /* in */ *palette);

SIXELAPI void
sixel_dither_set_complexion_score(
    sixel_dither_t /* in */ *dither,   /* dither context object */
    int            /* in */ score);    /* complexion score (>= 1) */

SIXELAPI void
sixel_dither_set_body_only(
    sixel_dither_t /* in */ *dither,   /* dither context object */
    int            /* in */ bodyonly); /* 0: output palette section(default)
                                          1: do not output palette section */
SIXELAPI void
sixel_dither_set_optimize_palette(
    sixel_dither_t /* in */ *dither,   /* dither context object */
    int            /* in */ do_opt);   /* 0: optimize palette size
                                          1: don't optimize palette size */
/* set pixelformat */
SIXELAPI void
sixel_dither_set_pixelformat(
    sixel_dither_t /* in */ *dither,      /* dither context object */
    int            /* in */ pixelformat); /* one of enum pixelFormat */

/* set transparent */
SIXELAPI void
sixel_dither_set_transparent(
    sixel_dither_t /* in */ *dither,      /* dither context object */
    int            /* in */ transparent); /* transparent color index */

Output context

Here is a part of APIs for output context manipulation.

/* create output context object */
SIXELAPI SIXELSTATUS
sixel_output_new(
    sixel_output_t          /* out */ **output,     /* output object to be created */
    sixel_write_function    /* in */  fn_write,     /* callback for output sixel */
    void                    /* in */ *priv,         /* private data given as
                                                       3rd argument of fn_write */
    sixel_allocator_t       /* in */  *allocator);  /* allocator, null if you use
                                                       default allocator */

/* destroy output context object */
SIXELAPI void
sixel_output_destroy(sixel_output_t /* in */ *output); /* output context */

/* increase reference count of output context object (thread-unsafe) */
SIXELAPI void
sixel_output_ref(sixel_output_t /* in */ *output);     /* output context */

/* decrease reference count of output context object (thread-unsafe) */
SIXELAPI void
sixel_output_unref(sixel_output_t /* in */ *output);   /* output context */

/* set 8bit output mode which indicates whether it uses C1 control characters */
SIXELAPI int
sixel_output_get_8bit_availability(
    sixel_output_t /* in */ *output);   /* output context */

/* get 8bit output mode state */
SIXELAPI void
sixel_output_set_8bit_availability(
    sixel_output_t /* in */ *output,       /* output context */
    int            /* in */ availability); /* 0: do not use 8bit characters
                                              1: use 8bit characters */

/* set GNU Screen penetration feature enable or disable */
SIXELAPI void
sixel_output_set_penetrate_multiplexer(
    sixel_output_t /* in */ *output,    /* output context */
    int            /* in */ penetrate); /* 0: penetrate GNU Screen
                                           1: do not penetrate GNU Screen */

/* set whether we skip DCS envelope */
SIXELAPI void
sixel_output_set_skip_dcs_envelope(
    sixel_output_t /* in */ *output,   /* output context */
    int            /* in */ skip);     /* 0: output DCS envelope
                                          1: do not output DCS envelope */

SIXELAPI void
sixel_output_set_palette_type(
    sixel_output_t /* in */ *output,      /* output context */
    int            /* in */ palettetype); /* PALETTETYPE_RGB: RGB palette
                                             PALETTETYPE_HLS: HLS palette */

SIXELAPI void
sixel_output_set_encode_policy(
    sixel_output_t /* in */ *output,    /* output context */
    int            /* in */ encode_policy);

SIXEL to indexed bitmap

sixel_decode function converts SIXEL into indexed bitmap bytes with its palette.

/* convert sixel data into indexed pixel bytes and palette data */
SIXELAPI SIXELSTATUS
sixel_decode_raw(
    unsigned char       /* in */  *p,           /* sixel bytes */
    int                 /* in */  len,          /* size of sixel bytes */
    unsigned char       /* out */ **pixels,     /* decoded pixels */
    int                 /* out */ *pwidth,      /* image width */
    int                 /* out */ *pheight,     /* image height */
    unsigned char       /* out */ **palette,    /* ARGB palette */
    int                 /* out */ *ncolors,     /* palette size (<= 256) */
    sixel_allocator_t   /* in */  *allocator);  /* allocator object */

Perl interface

This package includes a perl module Image::Sixel.

Build and install Perl interface

$ cd perl
$ perl Build.PL
$ ./Build test
$ ./Build install

Python interface

This package includes a Python module libsixel.

Build and install Python interface

Install into the python prefixed with '/usr/local'

$ git clone https://github.com/saitoha/libsixel.git
$ cd libsixel
$ git checkout develop  # now available only develop branch
$ ./configure --enable-python --prefix=/usr/local
$ make install

Install into only current active python

$ git clone https://github.com/saitoha/libsixel.git
$ cd libsixel
$ git checkout develop  # now available only develop branch
$ ./configure --disable-python
$ make install  # install libsixel
$ cd python
$ python setup.py install  # install python module

or

$ easy_install libsixel-python

PHP interface

This package includes a PHP module sixel.

Build and install PHP interface

$ cd php/sixel
$ phpize
$ ./configure
$ make install

Ruby interface

Build and install Ruby interface

$ gem install libsixel-ruby

or

$ git submodule update --init
$ rake compile
$ rake build install

Support

This software is provided "as is" without express or implied warranty. The main support channel for this software is the github issue tracker:

https://github.com/saitoha/libsixel/issues

Please post your issue if you have any problems, questions or suggestions.

License

The MIT License (MIT)

Copyright (c) 2014 Hayaki Saito

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributers and Reviewers

Contributing

  1. Fork it ( https://github.com/saitoha/libsixel/fork/ )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Acknowledgment

This software derives from the following implementations.

sixel 2014-3-2

src/tosixel.c, src/fromsixel.c, and some part of converters/loader.c are derived from kmiya's "sixel" original version (2014-3-2)

Package: http://nanno.dip.jp/softlib/man/rlogin/sixel.tar.gz

Unofficial repo: https://github.com/saitoha/sixel

This work is written by kmiya@ culti. He distributes it under very permissive license.

The original license text(in Japanese) is:

このプログラム及びソースコードの使用について個人・商用を問わず

ご自由に使用していただいで結構です。

また、配布・転載・紹介もご連絡の必要もありません。

ソースの改変による配布も自由ですが、どのバージョンの改変かを

明記されることを希望します。

バージョン情報が無い場合は、配布物の年月日を明記されることを

希望します。

                  2014/10/05  kmiya

The unofficial translation:

Anyone is free to use this program for any purpose,
commercial or non-commercial, without any restriction.

Anyone is free to distribute, copy, publish, or
advertise this software, without any contact.

Anyone is free to distribute with modification of the
source code, but I "hope" that its based version or
date will be written clearly.

                                    2014/10/05 kmiya

kmiya also said this is compatible with MIT/BSD/GPL.

stbi-2.12

This software includes stb-image-v2.12 (stb_image.h), public domain JPEG/PNG reader.

https://github.com/nothings/stb

LICENSE

This software is in the public domain. Where that dedication is not recognized, you are granted a perpetual, irrevocable license to copy, distribute, and modify this file as you see fit.

stbiw-1.02

This software includes stb-image-write-v1.02 (stb_image_write.h), public domain PNG/BMP/TGA writer.

https://github.com/nothings/stb

LICENSE

This software is in the public domain. Where that dedication is not recognized, you are granted a perpetual, irrevocable license to copy, distribute, and modify this file as you see fit.

pnmquant.c (netpbm library)

The implementation of median cut algorithm for color quantization in quant.c is imported from pnmcolormap included in netpbm library.

http://netpbm.sourceforge.net/

pnmcolormap was derived from ppmquant, originally written by Jef Poskanzer.

Copyright (C) 1989, 1991 by Jef Poskanzer. Copyright (C) 2001 by Bryan Henderson.

Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. This software is provided "as is" without express or implied warranty.

loader.h (@uobikiemukot's sdump)

Some parts of converters/loader.c are imported from @uobikiemukot's sdump project

The MIT License (MIT)

Copyright (c) 2014 haru

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ax_gcc_var_attribute / ax_gcc_func_attribute

These are useful m4 macros for detecting some GCC attributes / built-in functions.

http://www.gnu.org/software/autoconf-archive/ax_gcc_var_attribute.html http://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html http://www.gnu.org/software/autoconf-archive/ax_gcc_builtin.html

Copyright (c) 2013 Gabriele Svelto [email protected]

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.

graphics.c (from Xterm pl#310)

The helper function hls2rgb in src/fromsixel.c is imported from graphics.c in Xterm pl#310, originally written by Ross Combs.

Copyright 2013,2014 by Ross Combs

                    All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization.

test images

http://public-domain-photos.com/

The following test images in "image/" directory came from PUBLIC-DOMAIN-PHOTOS.com.

These are in the public domain.

vimperator3.png (mascot of vimperator)

images/vimperator3.png is in the public domain.

author: @k_wizard
url: http://quadrantem.com/~k_wizard/vimprtan/

PngSuite

Images under the directory images/pngsuite/ are imported from PngSuite created by Willem van Schaik.

Permission to use, copy, modify and distribute these images for any purpose and without fee is hereby granted.

(c) Willem van Schaik, 1996, 2011

References

ImageMagick

We are greatly inspired by the quality of ImageMagick and added some resampling filters to img2sixel in reference to the line-up of filters of MagickCore's resize.c.

http://www.imagemagick.org/api/MagickCore/resize_8c_source.html

Similar software

  • netpbm

    You can get SIXEL graphics using ppmtosixel or pbmtoln03.

  • kmiya's sixel

    libgd based SIXEL converter

  • PySixel

    Python implementation of SIXEL converter

  • ImageMagick

    Now SIXEL coder is available in svn trunk and V6 branch.

  • monosixel in arakiken's tw

    A monochrome SIXEL converter

  • sixelv in sayaka-chan Vala version

    sayaka-chan(Vala version) also includes SIXEL converter.

  • rust-sixel

    A SIXEL encoder written in rust.

  • forth-sixel

    A SIXEL encoder written in forth.

  • ff2sixel

    An utility to convert farbfeld images to Sixels.

  • tv

    terminal/commandline image viewer

  • xpr(x11-apps)

    xpr(1) can convert a xwd(X window dump) format image into a sixel image with '-device ln03' or '-device la100' option. But now it is not maintained. It looks broken.

Other software supporting SIXEL

Comments
  • img2sixel で透過色の背景色として黒以外の色を指定できるようにして欲しい

    img2sixel で透過色の背景色として黒以外の色を指定できるようにして欲しい

    掲題の通りですが、もし何らかの方法で透過色の背景色を指定できるようでしたらその方法を教えていただけないでしょうか?

    ちなみに、実際に困ったシチュエーションは http://www.fileformat.info/info/unicode/char/01dd/index.htm の http://www.fileformat.info/info/unicode/char/01dd/latin_small_letter_turned_e.png を w3m で表示しようとした時です。

    enhancement 
    opened by msmhrt 21
  • GIF画像を表示すると多数のノイズが乗る

    GIF画像を表示すると多数のノイズが乗る

    OS: Ubuntu 14.04.1 (amd64) Terminal: mlterm 最新版( https://bitbucket.org/arakiken/mlterm/commits/b2997e9c235db39ab79d3cf4c167c23796c0a5bb?at=default )

    master ブランチの現在の HEAD ( https://github.com/saitoha/libsixel/commit/cdc6005baf76951e77ea926282d572fa5f2a678f ) でビルドした img2sixel

    before

    ( before.gif )を表示すると、

    after

    ( after.png )のように表示され、多数のノイズが乗ってしまいます。

    上の画像は透過GIF画像を convert コマンドで不透過にした物です。具体的には

    $ wget -O - "http://static.syosetu.com/view/images/syuppan_logo.gif?mvxta7" | convert -  \( +clone -alpha opaque -fill "#300824" -colorize 100% \) +swap -geometry +0+0 -compose Over -composite -alpha off before.gif
    

    で作成しています。 下の画像は

    $ img2sixel before.gif | sixel2png after.png
    

    で作成していますので、端末側の問題ではないと思われます。

    img2sixel-d オプションで fsauto 以外にした場合はノイズがありませんでしたので、特定のディザリング方式が影響しているのではないかと思われます。 (ついでで申し訳ないのですが、最大256色のGIF画像をディザリングしている理由がちょっと分からなかったので教えていただけないでしょうか?)

    -I オプションを追加した場合もノイズがありませんでした。

    bug enhancement 
    opened by msmhrt 17
  • Invalid free wild pointer lead to DOS in load_png in loader.c

    Invalid free wild pointer lead to DOS in load_png in loader.c

    load_png has a pointer rows, which should be set to NULL, otherwise cleanup code would use(calling free) it.

    binary: img2sixel file: loader.c function: load_png

    poc: poc.zip

    result:

    #0  __GI_raise (sig=sig@entry=0x6) at ../sysdeps/unix/sysv/linux/raise.c:51
    #1  0x00007ffff6fcf801 in __GI_abort () at abort.c:79
    #2  0x00007ffff7018897 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff7145b9a "%s\n") at ../sysdeps/posix/libc_fatal.c:181
    #3  0x00007ffff701f90a in malloc_printerr (str=str@entry=0x7ffff7143d88 "free(): invalid pointer") at malloc.c:5350
    #4  0x00007ffff7026e1c in _int_free (have_lock=0x0, p=0x65a5b8, av=0x7ffff737ac40 <main_arena>) at malloc.c:4157
    #5  __GI___libc_free (mem=0x65a5c8) at malloc.c:3124
    #6  0x0000000000426701 in load_png (result=<optimized out>, buffer=<optimized out>, size=<optimized out>, psx=<optimized out>, psy=0x65a5dc, ppalette=<optimized out>, pncolors=0x65a5e0, reqcolors=0x100, pixelformat=0x65a5e4,
        bgcolor=0x0, transparent=0x65a5f8, allocator=0x652260) at loader.c:633
    #7  0x0000000000410e2b in load_with_builtin (pchunk=<optimized out>, fstatic=0x0, fuse_palette=0x1, reqcolors=<optimized out>, bgcolor=<optimized out>, loop_control=0x0, fn_load=<optimized out>, context=<optimized out>) at loader.c:889
    #8  sixel_helper_load_image_file (filename=<optimized out>, fstatic=0x0, fuse_palette=0x1, reqcolors=0x100, bgcolor=<optimized out>, loop_control=0x0, fn_load=<optimized out>, finsecure=<optimized out>, cancel_flag=<optimized out>,
        context=<optimized out>, allocator=<optimized out>) at loader.c:1418
    #9  0x0000000000403d93 in sixel_encoder_encode (encoder=0x652290, filename=0x7fffffffe634 "/tmp/crashes/id:000001,sig:11,src:000624,op:havoc,rep:4") at encoder.c:1743
    #10 0x000000000040272d in main (argc=<optimized out>, argc@entry=0x2, argv=<optimized out>, argv@entry=0x7fffffffe388) at img2sixel.c:457
    #11 0x00007ffff6fb0b97 in __libc_start_main (main=0x402010 <main>, argc=0x2, argv=0x7fffffffe388, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe378) at ../csu/libc-start.c:310
    #12 0x0000000000401f4a in _start ()
    
    opened by sleicasper 12
  • img2sixel で libpng を使用すると http://www.schaik.com/pngsuite/basn0g01.png をリサイズした結果が表示されない

    img2sixel で libpng を使用すると http://www.schaik.com/pngsuite/basn0g01.png をリサイズした結果が表示されない

    【概要】 img2sixel で libpng を使用すると http://www.schaik.com/pngsuite/basn0g01.png をリサイズした結果が表示されない

    【発生環境】 OS: Ubuntu 14.04.2 LTS (amd64) Terminal: mlterm version 3.4.3 post/2015-02-22

    【詳細】 libpng を使用するようにビルドした master ブランチ( https://github.com/saitoha/libsixel/commit/7efd9a4bb4f95d7842fe7cec3b9cf8f48f009804 ) の img2sixel-h オプションまたは -w オプションを指定(例: -h 32)して http://www.schaik.com/pngsuite/basn0g01.png を表示しようとすると何も表示されません。

    stb_image を使用するようにビルドすれば問題ない画像が表示されます。

    develop ブランチ( https://github.com/saitoha/libsixel/commit/bf23ab67f59a660320c806b83f391155fc11d622) でも上記と同様の結果になりました。

    以下は使用した libpng12-dev の詳細です。

    l$ apt-cache show libpng12-dev
    Package: libpng12-dev
    Priority: optional
    Section: libdevel
    Installed-Size: 655
    Maintainer: Ubuntu Developers <[email protected]>
    Original-Maintainer: Anibal Monsalve Salazar <[email protected]>
    Architecture: amd64
    Source: libpng
    Version: 1.2.50-1ubuntu2
    Replaces: libpng12-0-dev, libpng3-dev (<= 1.2.5)
    Provides: libpng-dev, libpng12-0-dev, libpng3-dev
    Depends: libpng12-0 (= 1.2.50-1ubuntu2), zlib1g-dev
    Conflicts: libpng-dev, libpng12-0-dev, libpng2 (<< 1.0.12-3), libpng2-dev
    Filename: pool/main/libp/libpng/libpng12-dev_1.2.50-1ubuntu2_amd64.deb
    Size: 206078
    MD5sum: 1c94d131e03fc495db6b898686c5fea5
    SHA1: f506b031df4a3d2d6de1098f72da52fce246644f
    SHA256: f11324fe7f2432d3af9d2ce179fb7ebc34591ea18b3f0f55e1315d815a912168
    Description-ja: PNG ライブラリ - 開発用
     libpng は PNG (ポータブルネットワークグラフィックス) 形式のファイルの読み書
     きを行なうためのインターフェースを実装したライブラリです。
     .
     本パッケージには、libpng を使うプログラムやパッケージを構築するのに必要 なヘッダと開発用ファイルが含まれています。
    Description-md5: 748198d86eeddc4aa1418e7d1311203c
    Homepage: http://libpng.org/pub/png/libpng.html
    Bugs: https://bugs.launchpad.net/ubuntu/+filebug
    Origin: Ubuntu
    Supported: 5y
    
    $
    
    bug Not Implemented 
    opened by msmhrt 11
  • Unexpected hangs/performance issues

    Unexpected hangs/performance issues

    As of 2df6437, when running img2sixel $FILE -o /tmp/test.six, it may cause some unexpected hangs (may be because infinite loop, haven't looked into them) or there are some performance issues (specially for some crafted PSD files).

    The files in this directory on my machine took more than 10s to execute.

    bug 
    opened by hongxuchen 10
  •  munmap_chunk(): invalid pointer が発生する

    munmap_chunk(): invalid pointer が発生する

    release-1.4 ブランチ( https://github.com/saitoha/libsixel/commit/80ec152c6b54454d610eb165c13484b87879ffa7 )で、munmap_chunk(): invalid pointer というエラーが表示されました。

    再現率は 10/10回 で master ブランチ( https://github.com/saitoha/libsixel/commit/cdc6005baf76951e77ea926282d572fa5f2a678f )でも発生しましたが、develop ブランチ( https://github.com/saitoha/libsixel/commit/f80cf2a994d4eb04972bda04537321309671545b )では発生しませんでした。

    下記は全ログです。

    $ wget -O - "https://www.google.com/images/icons/product/youtube-16.png" | img2sixel
    --2015-02-15 22:49:28--  https://www.google.com/images/icons/product/youtube-16.png
    Resolving www.google.com (www.google.com)... 173.194.72.106, 173.194.72.99, 173.194.72.147, ...
    Connecting to www.google.com (www.google.com)|173.194.72.106|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 186 [image/png]
    Saving to: 'STDOUT'
    
    100%[===================================================================================>] 186         --.-K/s   in 0s
    
    2015-02-15 22:49:28 (20.4 MB/s) - written to stdout [186/186]
    
    *** Error in `img2sixel': munmap_chunk(): invalid pointer: 0x0000000001592a40 ***
    Aborted
    $
    

    下記は gdbbt した結果です。

    $ gdb img2sixel
    GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
    Copyright (C) 2014 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from img2sixel...done.
    (gdb) run youtube-16.png
    Starting program: /home/msmhrt/local/bin/img2sixel youtube-16.png
    *** Error in `/home/msmhrt/local/bin/img2sixel': munmap_chunk(): invalid pointer: 0x0000000000630aa0 ***
    
    Program received signal SIGABRT, Aborted.
    0x00007ffff70bfcc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
    56      ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
    (gdb) bt
    #0  0x00007ffff70bfcc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
    #1  0x00007ffff70c30d8 in __GI_abort () at abort.c:89
    #2  0x00007ffff70fcf24 in __libc_message (do_abort=do_abort@entry=1,
        fmt=fmt@entry=0x7ffff720b6c8 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
    #3  0x00007ffff7107c87 in malloc_printerr (action=<optimized out>, str=0x7ffff720ba48 "munmap_chunk(): invalid pointer",
        ptr=<optimized out>) at malloc.c:4996
    #4  0x000000000040fc13 in load_png (pixelformat=0x7fffffffdfe4, reqcolors=256, pncolors=0x7fffffffdfe0,
        ppalette=0x7fffffffe010, pcomp=0x7fffffffdeac, psy=0x7fffffffdfd4, psx=0x7fffffffdfd0, size=<optimized out>,
        buffer=0x61c250 "\211PNG\r\n\032\n") at loader.c:434
    #5  load_with_builtin (reqcolors=256, fstatic=0, ppdelay=0x7fffffffe008, ploop_count=0x7fffffffdfdc,
        pframe_count=0x7fffffffdfd8, ppixelformat=0x7fffffffdfe4, pncolors=0x7fffffffdfe0, ppalette=0x7fffffffe010,
        pstride=<synthetic pointer>, pcomp=0x7fffffffdeac, psy=0x7fffffffdfd4, psx=0x7fffffffdfd0, pchunk=<synthetic pointer>)
        at loader.c:663
    #6  load_image_file (filename=filename@entry=0x7fffffffe8d6 "youtube-16.png", psx=psx@entry=0x7fffffffdfd0,
        psy=psy@entry=0x7fffffffdfd4, ppalette=ppalette@entry=0x7fffffffe010, pncolors=pncolors@entry=0x7fffffffdfe0,
        ppixelformat=ppixelformat@entry=0x7fffffffdfe4, pframe_count=pframe_count@entry=0x7fffffffdfd8,
        ploop_count=ploop_count@entry=0x7fffffffdfdc, ppdelay=ppdelay@entry=0x7fffffffe008, fstatic=0, reqcolors=256,
        ppixels=ppixels@entry=0x7fffffffe000) at loader.c:1046
    #7  0x0000000000404209 in convert_to_sixel (filename=0x7fffffffe8d6 "youtube-16.png",
        psettings=psettings@entry=0x7fffffffe110) at img2sixel.c:812
    #8  0x00000000004034e1 in main (argc=2, argv=<optimized out>) at img2sixel.c:1676
    (gdb)
    

    既知問題でしたらすみません。

    bug 
    opened by msmhrt 10
  • img2sixel で images/snake-progressive.jpg を表示できない

    img2sixel で images/snake-progressive.jpg を表示できない

    img2sixel で images/snake-progressive.jpg を表示しようとすると下記のエラーが表示されます。

    $ img2sixel images/snake-progressive.jpg
    stbi_load_from_file failed.
    reason: progressive jpeg.
    $
    

    発生環境は、 https://github.com/saitoha/libsixel/issues/23 と同じです。 (すみません。上記の Issue で他の画像は問題ないと報告したのですが、見逃していたようです。)

    以下は単なる案ですが、ヘッダの細かい違いの影響を避けるために画像データを raw 出力してから、その md5 を make check でチェックするようにすると良いのかもしれませんね。 (浮動小数点演算の精度とかが厄介かもしれませんが)

    enhancement 
    opened by msmhrt 10
  • Completion of error handling

    Completion of error handling

    opened by elfring 8
  • two bugs in img2sixel and sixel2png

    two bugs in img2sixel and sixel2png

    ./sixel2png infinite_loop_poc1

    ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[ source:../../src/fromsixel.c+561 ]────
        556	             default:
        557	                 if (*p >= '?' && *p <= '~') {  /* sixel characters */
        558	                     if (image->width < (context->pos_x + context->repeat_count) || image->height < (context->pos_y + 6)) {
        559	                         sx = image->width * 2;
        560	                         sy = image->height * 2;
    		// context=0x00007fffffffd6a0  →  [...]  →  0x0000000000000003, sx=0x0, sy=-0x80000000
     →  561	                         while (sx < (context->pos_x + context->repeat_count) || sy < (context->pos_y + 6)) {
        562	                             sx *= 2;
        563	                             sy *= 2;
        564	                         }
        565	                         status = image_buffer_resize(image, sx, sy, context->bgindex, allocator);
        566	                         if (SIXEL_FAILED(status)) {
    ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[ threads ]────
    [#0] Id 1, Name: "sixel2png", stopped, reason: SINGLE STEP
    ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[ trace ]────
    [#0] 0x7ffff7b7ed89 → Name: sixel_decode_raw_impl(p=0x555555774630 "^\033\\", len=0x53, image=0x7fffffffd7e0, context=0x7fffffffd760, allocator=0x555555774300)
    [#1] 0x7ffff7b7f8b3 → Name: sixel_decode_raw(p=0x5555557745e0 "\033Pq\"1;1;70;11#1;2;", '1' <repeats 13 times>, "9;19;19#0!70~-!7", '1' <repeats 25 times>, "\"1111110^\033\\", len=0x53, pixels=0x7fffffffdc58, pwidth=0x7fffffffdc3c, pheight=0x7fffffffdc40, palette=0x7fffffffdc60, ncolors=0x7fffffffdc44, allocator=0x555555774300)
    [#2] 0x7ffff7bacc8c → Name: sixel_decoder_decode(decoder=0x555555774330)
    [#3] 0x555555554ea6 → Name: main(argc=0x2, argv=0x7fffffffde68)
    ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    561	                        while (sx < (context->pos_x + context->repeat_count) || sy < (context->pos_y + 6)) {
    1: sx = 0x0
    gef➤  p context->pos_x + context->repeat_count
    $32 = 0x471c71c7
    
    

    ./img2sixel heap-buffer-overflow-poc2

    Corrupt JPEG data: premature end of data segment
    =================================================================
    ==100553==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7fc919e46f94 at pc 0x7fca3cf50228 bp 0x7fffe7f5e600 sp 0x7fffe7f5e5f8
    READ of size 1 at 0x7fc919e46f94 thread T0
    ==100553==WARNING: failed to fork (errno 12)
    ==100553==WARNING: failed to fork (errno 12)
    ==100553==WARNING: failed to fork (errno 12)
    ==100553==WARNING: failed to fork (errno 12)
    ==100553==WARNING: failed to fork (errno 12)
    ==100553==WARNING: Failed to use and restart external symbolizer!
        #0 0x7fca3cf50227  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0x70227)
        #1 0x7fca3cf4c758  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0x6c758)
        #2 0x7fca3cf53ae5  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0x73ae5)
        #3 0x7fca3cf36b25  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0x56b25)
        #4 0x7fca3d028e26  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0x148e26)
        #5 0x7fca3cf88581  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0xa8581)
        #6 0x7fca3d0264de  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0x1464de)
        #7 0x50564a  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/bin/img2sixel+0x50564a)
        #8 0x7fca3bf2fb96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
        #9 0x41c139  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/bin/img2sixel+0x41c139)
    
    0x7fc919e46f94 is located 0 bytes to the right of 433805204-byte region [0x7fc900091800,0x7fc919e46f94)
    allocated by thread T0 here:
        #0 0x4cb710  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/bin/img2sixel+0x4cb710)
        #1 0x7fca3d028ba1  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0x148ba1)
        #2 0x7fca3cf88581  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0xa8581)
        #3 0x7fca3d0264de  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0x1464de)
        #4 0x50564a  (/home/fish/Desktop/dumb/image/libsixel/fast/fast/bin/img2sixel+0x50564a)
        #5 0x7fca3bf2fb96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    
    SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/fish/Desktop/dumb/image/libsixel/fast/fast/lib/libsixel.so.1+0x70227) 
    Shadow bytes around the buggy address:
      0x0ff9a33c0da0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0ff9a33c0db0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0ff9a33c0dc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0ff9a33c0dd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0ff9a33c0de0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    =>0x0ff9a33c0df0: 00 00[04]fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0ff9a33c0e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0ff9a33c0e10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0ff9a33c0e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0ff9a33c0e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0ff9a33c0e40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
    Shadow byte legend (one shadow byte represents 8 application bytes):
      Addressable:           00
      Partially addressable: 01 02 03 04 05 06 07 
      Heap left redzone:       fa
      Heap right redzone:      fb
      Freed heap region:       fd
      Stack left redzone:      f1
      Stack mid redzone:       f2
      Stack right redzone:     f3
      Stack partial redzone:   f4
      Stack after return:      f5
      Stack use after scope:   f8
      Global redzone:          f9
      Global init order:       f6
      Poisoned by user:        f7
      Container overflow:      fc
      Array cookie:            ac
      Intra object redzone:    bb
      ASan internal:           fe
      Left alloca redzone:     ca
      Right alloca redzone:    cb
    ==100553==ABORTING
    
    
    gef➤  bt
    #0  __memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:249
    #1  0x00007ffff7ba4bae in load_jpeg (result=0x555555777428, data=0x7ffff7fd4010 "\377\330\377", <incomplete sequence \340>, datasize=0x1263b, pwidth=0x555555777438, pheight=0x55555577743c, ppixelformat=0x555555777444, allocator=0x555555777300) at ../../src/loader.c:198
    #2  0x00007ffff7ba62d7 in load_with_builtin (pchunk=0x5555557773f0, fstatic=0x0, fuse_palette=0x1, reqcolors=0x100, bgcolor=0x0, loop_control=0x0, fn_load=0x7ffff7bac395 <load_image_callback>, context=0x555555777330) at ../../src/loader.c:820
    #3  0x00007ffff7ba67d1 in sixel_helper_load_image_file (filename=0x7fffffffe247 "/home/fish/testcase/images/jpg/random.jpg", fstatic=0x0, fuse_palette=0x1, reqcolors=0x100, bgcolor=0x0, loop_control=0x0, fn_load=0x7ffff7bac395 <load_image_callback>, finsecure=0x0, cancel_flag=0x555555759014 <signaled>, context=0x555555777330, allocator=0x555555777300) at ../../src/loader.c:1352
    #4  0x00007ffff7bac50e in sixel_encoder_encode (encoder=0x555555777330, filename=0x7fffffffe247 "/home/fish/testcase/images/jpg/random.jpg") at ../../src/encoder.c:1737
    #5  0x0000555555555545 in main (argc=0x2, argv=0x7fffffffde78) at ../../converters/img2sixel.c:457
    
    
    opened by cool-tomato 7
  • develop ブランチ で *** Error in `img2sixel': double free or corruption (!prev) が発生する

    develop ブランチ で *** Error in `img2sixel': double free or corruption (!prev) が発生する

    【概要】 develop ブランチ で *** Error inimg2sixel': double free or corruption (!prev)` が発生する

    【発生環境】 OS: Ubuntu 14.04.2 LTS (amd64) Terminal: mlterm version 3.4.3 post/2015-02-22 libpng: 1.2.50-1ubuntu2

    【詳細】 develop ブランチ( https://github.com/saitoha/libsixel/commit/e953d9cd19f7e9416565ed7af12722133ab544fb ) の img2sixel で http://cdn1.www.st-hatena.com/users/ha/harukamaid/profile_l.gif を表示しようとすると下記のエラーが発生します。

    $ wget -O - "http://cdn1.www.st-hatena.com/users/ha/harukamaid/profile_l.gif" | img2sixe
    l
    --2015-03-04 04:50:01--  http://cdn1.www.st-hatena.com/users/ha/harukamaid/profile_l.gif
    Resolving cdn1.www.st-hatena.com (cdn1.www.st-hatena.com)... 210.149.5.41, 210.149.5.16
    Connecting to cdn1.www.st-hatena.com (cdn1.www.st-hatena.com)|210.149.5.41|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 2180 (2.1K) [image/gif]
    Saving to: 'STDOUT'
    
    100%[===================================================================================>] 2,180       --.-K/s   in 0s
    
    2015-03-04 04:50:01 (192 MB/s) - written to stdout [2180/2180]
    
    *** Error in `img2sixel': double free or corruption (!prev): 0x00000000013a1020 ***
    Aborted
    $
    

    master ブランチ ( https://github.com/saitoha/libsixel/commit/7f7358573f7e4957dd483689782bfc3c127ceba6 ) では下記のエラーが表示されました。

    stbi_load_from_file failed.
    reason: unknown code.
    

    画像を表示できないのが現状の制限または正しい仕様だった場合、こちらのエラーが表示されるべきだと思います。

    下記は develop ブランチ( https://github.com/saitoha/libsixel/commit/e953d9cd19f7e9416565ed7af12722133ab544fb ) の img2sixel を使って gdbbt した結果です。

    $ gdb img2sixel
    GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
    Copyright (C) 2014 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from img2sixel...done.
    (gdb) run profile_l.gif
    Starting program: /home/msmhrt/local/bin/img2sixel profile_l.gif
    *** Error in `/home/msmhrt/local/bin/img2sixel': double free or corruption (!prev): 0x0000000000619260 ***
    
    Program received signal SIGABRT, Aborted.
    0x00007ffff7827cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
    56      ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
    (gdb) bt
    #0  0x00007ffff7827cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
    #1  0x00007ffff782b0d8 in __GI_abort () at abort.c:89
    #2  0x00007ffff7864394 in __libc_message (do_abort=do_abort@entry=1,
        fmt=fmt@entry=0x7ffff7972b28 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
    #3  0x00007ffff787066e in malloc_printerr (ptr=<optimized out>, str=0x7ffff7972c10 "double free or corruption (!prev)",
        action=1) at malloc.c:4996
    #4  _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3840
    #5  0x00007ffff7bcc432 in load_with_builtin (bgcolor=0x0, reqcolors=256, fstatic=0, ppdelay=0x7fffffffdf18,
        ploop_count=0x7fffffffdeec, pframe_count=0x7fffffffdee8, ppixelformat=0x7fffffffdef4, pncolors=0x7fffffffdef0,
        ppalette=<optimized out>, pstride=<synthetic pointer>, psy=0x7fffffffdee4, psx=0x7fffffffdee0,
        pchunk=<synthetic pointer>) at loader.c:986
    #6  sixel_helper_load_image_file (ppixels=ppixels@entry=0x7fffffffdf10, ppalette=ppalette@entry=0x7fffffffdf20,
        psx=psx@entry=0x7fffffffdee0, psy=psy@entry=0x7fffffffdee4, pncolors=pncolors@entry=0x7fffffffdef0,
        ppixelformat=ppixelformat@entry=0x7fffffffdef4, pframe_count=pframe_count@entry=0x7fffffffdee8,
        ploop_count=ploop_count@entry=0x7fffffffdeec, ppdelay=ppdelay@entry=0x7fffffffdf18,
        filename=filename@entry=0x7fffffffe84e "profile_l.gif", fstatic=0, reqcolors=256, bgcolor=0x0) at loader.c:1368
    #7  0x00000000004037e6 in convert_to_sixel (filename=<optimized out>, psettings=psettings@entry=0x7fffffffe020)
        at img2sixel.c:919
    #8  0x0000000000402a10 in main (argc=2, argv=<optimized out>) at img2sixel.c:1808
    (gdb)
    
    bug 
    opened by msmhrt 7
  • images/snake-monochrome.png が正しく表示されない

    images/snake-monochrome.png が正しく表示されない

    OS: Ubuntu 14.04.1 (amd64) Terminal: mlterm 最新版( https://bitbucket.org/arakiken/mlterm/commits/b2997e9c235db39ab79d3cf4c167c23796c0a5bb?at=default )

    master ブランチの現在の HEAD ( https://github.com/saitoha/libsixel/commit/d01f0d93408d431b9fbf72cc838bf191d8caccc5 ) でビルドした img2sixelimages/snake-monochrome.png を表示すると、下記の画像のように表示されてしまう。

    error_1

    images/ 内の他の画像については問題ないようです。

    bug 
    opened by msmhrt 7
  • img2sixel: error while loading shared libraries: libsixel.so.1: cannot open shared object file: No such file or directory

    img2sixel: error while loading shared libraries: libsixel.so.1: cannot open shared object file: No such file or directory

    I've got this error. How can I resolve it?

    Env Windows10home WSL2 ubuntu22.04

    Command I used to install

    git clone REPO_DIR
    cd REPO_DIR
    ./configure
    make
    make install
    
    opened by PorcoRosso85 0
  • heap-buffer-overflow in error_diffuse, quant.c:876, different from #156

    heap-buffer-overflow in error_diffuse, quant.c:876, different from #156

    Description

    There is a heap-buffer-overflow error in img2sixel 1.8.6 in error_diffuse, quant.c:876, which is invoked by diffuse_jajuni, quant.c:972 (different from #156). Remote attackers could leverage this vulnerability to cause a denial-of-service via a crafted JPEG file.

    Version

    $ img2sixel -V
    img2sixel 1.8.6
    
    configured with:
      libcurl: yes
      libpng: yes
      libjpeg: yes
      gdk-pixbuf2: no
      GD: no
    

    Reproduction

    $ img2sixel -d jajuni  -b vt340mono poc /tmp/foo
    =================================================================
    ==135878==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6030000010ed at pc 0x55e064953e8e bp 0x7ffda7711e50 sp 0x7ffda7711e40
    READ of size 1 at 0x6030000010ed thread T0
        #0 0x55e064953e8d in error_diffuse /root/programs_latest/libsixel/src/quant.c:876
        #1 0x55e0649541ff in diffuse_jajuni /root/programs_latest/libsixel/src/quant.c:972
        #2 0x55e064956a85 in sixel_quant_apply_palette /root/programs_latest/libsixel/src/quant.c:1449
        #3 0x55e064904e97 in sixel_dither_apply_palette /root/programs_latest/libsixel/src/dither.c:801
        #4 0x55e0648faca9 in sixel_encode_dither /root/programs_latest/libsixel/src/tosixel.c:830
        #5 0x55e064902b7f in sixel_encode /root/programs_latest/libsixel/src/tosixel.c:1551
        #6 0x55e0648ee0e0 in sixel_encoder_output_without_macro /root/programs_latest/libsixel/src/encoder.c:825
        #7 0x55e0648ef381 in sixel_encoder_encode_frame /root/programs_latest/libsixel/src/encoder.c:1056
        #8 0x55e0648f3245 in load_image_callback /root/programs_latest/libsixel/src/encoder.c:1679
        #9 0x55e064943c67 in load_with_builtin /root/programs_latest/libsixel/src/loader.c:963
        #10 0x55e0649441aa in sixel_helper_load_image_file /root/programs_latest/libsixel/src/loader.c:1418
        #11 0x55e0648f36a9 in sixel_encoder_encode /root/programs_latest/libsixel/src/encoder.c:1743
        #12 0x55e0648e965b in main /root/programs_latest/libsixel/converters/img2sixel.c:457
        #13 0x7f8f97ce2082 in __libc_start_main ../csu/libc-start.c:308
        #14 0x55e0648e6fad in _start (/root/programs_latest/libsixel/build_asan/bin/img2sixel+0x39fad)
    
    0x6030000010ed is located 3 bytes to the left of 18-byte region [0x6030000010f0,0x603000001102)
    allocated by thread T0 here:
        #0 0x7f8f9829c808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
        #1 0x55e0648e986e in rpl_malloc /root/programs_latest/libsixel/converters/malloc_stub.c:45
        #2 0x55e0648f4524 in sixel_allocator_malloc /root/programs_latest/libsixel/src/allocator.c:162
        #3 0x55e0648ede50 in sixel_encoder_output_without_macro /root/programs_latest/libsixel/src/encoder.c:789
        #4 0x55e0648ef381 in sixel_encoder_encode_frame /root/programs_latest/libsixel/src/encoder.c:1056
        #5 0x55e0648f3245 in load_image_callback /root/programs_latest/libsixel/src/encoder.c:1679
        #6 0x55e064943c67 in load_with_builtin /root/programs_latest/libsixel/src/loader.c:963
        #7 0x55e0649441aa in sixel_helper_load_image_file /root/programs_latest/libsixel/src/loader.c:1418
        #8 0x55e0648f36a9 in sixel_encoder_encode /root/programs_latest/libsixel/src/encoder.c:1743
        #9 0x55e0648e965b in main /root/programs_latest/libsixel/converters/img2sixel.c:457
        #10 0x7f8f97ce2082 in __libc_start_main ../csu/libc-start.c:308
    
    SUMMARY: AddressSanitizer: heap-buffer-overflow /root/programs_latest/libsixel/src/quant.c:876 in error_diffuse
    Shadow bytes around the buggy address:
      0x0c067fff81c0: 00 00 fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa
      0x0c067fff81d0: 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00 00 00
      0x0c067fff81e0: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
      0x0c067fff81f0: 00 00 fa fa 00 00 00 fa fa fa 00 00 00 fa fa fa
      0x0c067fff8200: 00 00 00 fa fa fa 00 00 00 fa fa fa 00 00 00 fa
    =>0x0c067fff8210: fa fa 00 00 00 00 fa fa 00 00 02 fa fa[fa]00 00
      0x0c067fff8220: 02 fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c067fff8230: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c067fff8240: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c067fff8250: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c067fff8260: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
    Shadow byte legend (one shadow byte represents 8 application bytes):
      Addressable:           00
      Partially addressable: 01 02 03 04 05 06 07 
      Heap left redzone:       fa
      Freed heap region:       fd
      Stack left redzone:      f1
      Stack mid redzone:       f2
      Stack right redzone:     f3
      Stack after return:      f5
      Stack use after scope:   f8
      Global redzone:          f9
      Global init order:       f6
      Poisoned by user:        f7
      Container overflow:      fc
      Array cookie:            ac
      Intra object redzone:    bb
      ASan internal:           fe
      Left alloca redzone:     ca
      Right alloca redzone:    cb
      Shadow gap:              cc
    ==135878==ABORTING
    

    poc.zip

    Platform

    # uname -a
    Linux dd189b3c7b86 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
    
    opened by waugustus 0
  • Feature request: Add palette mapping for VT240

    Feature request: Add palette mapping for VT240

    Currently, conversion for display of images on a real VT240 using -p 4 always displays the same 4 colours: red, green, blue, black. However, the sixel support on a VT240 actually can display 4 colours chosen from a palette of 64 colours. The fixed palette is documented on page 162 of this PDF:

    http://bitsavers.org/pdf/dec/terminal/vt240/EK-VT240-RM-002_VT240_Programmer_Reference_Manual_Oct84.pdf

    Could output matching these colours be achieved with a mapfile? And, if so, can a standard VT240 mapfile be added to the distribution?

    Love your library. Thanks for your hard work.

    opened by wohali 4
  • A jpeg causes img2sixel to crash with an integer overflow

    A jpeg causes img2sixel to crash with an integer overflow

    $ sixel2png lolwut.jpg
    runtime error: integer overflow
    safe_addition_for_params: ingeger overflow detected.
    

    And here's the image that provokes this error.

    lolwut

    No, I'm not kidding. I went through a few of my favorite images and img2sixel barfed on this one.

    opened by DavidGriffith 1
  • FPE in sixel_encoder_do_resize, encoder.c:636

    FPE in sixel_encoder_do_resize, encoder.c:636

    Description

    There is a floating point exception error in sixel_encoder_do_resize, encoder.c:636 in img2sixel 1.8.6. Remote attackers could leverage this vulnerability to cause a denial-of-service via a crafted JPEG file.

    Version

    $ img2sixel -V
    img2sixel 1.8.6
    
    configured with:
      libcurl: yes
      libpng: yes
      libjpeg: yes
      gdk-pixbuf2: no
      GD: no
    

    Reproduction

    # img2sixel -h 128 poc /tmp/foo
    ASAN:DEADLYSIGNAL
    =================================================================
    ==363283==ERROR: AddressSanitizer: FPE on unknown address 0x55890ff6ea81 (pc 0x55890ff6ea81 bp 0x7ffc4b1bb790 sp 0x7ffc4b1bb760 T0)
        #0 0x55890ff6ea80 in sixel_encoder_do_resize /root/cov_test/libsixel/src/encoder.c:636
        #1 0x55890ff6fdf0 in sixel_encoder_encode_frame /root/cov_test/libsixel/src/encoder.c:968
        #2 0x55890ff743a9 in load_image_callback /root/cov_test/libsixel/src/encoder.c:1679
        #3 0x55890ffca596 in load_gif /root/cov_test/libsixel/src/fromgif.c:671
        #4 0x55890ffc3f92 in load_with_builtin /root/cov_test/libsixel/src/loader.c:908
        #5 0x55890ffc4936 in sixel_helper_load_image_file /root/cov_test/libsixel/src/loader.c:1418
        #6 0x55890ff7480c in sixel_encoder_encode /root/cov_test/libsixel/src/encoder.c:1743
        #7 0x55890ff6aa0e in main /root/cov_test/libsixel/converters/img2sixel.c:457
        #8 0x7f02f1eebc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)
        #9 0x55890ff68359 in _start (/root/cov_test/libsixel/build_asan/bin/img2sixel+0x39359)
    
    AddressSanitizer can not provide additional info.
    SUMMARY: AddressSanitizer: FPE /root/cov_test/libsixel/src/encoder.c:636 in sixel_encoder_do_resize
    ==363283==ABORTING
    

    poc.zip

    Platform

    # uname -a
    Linux 4a409ce47130 5.4.0-70-generic #78~18.04.1-Ubuntu SMP Sat Mar 20 14:10:07 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
    
    opened by waugustus 1
Releases(v1.8.6)
  • v1.8.6(Jan 13, 2020)

  • v1.8.5(Jan 3, 2020)

    • Security fix for CVE-2019-20205 (#127), integer overflow problem, reported by @sleicasper.

    • Security fix for CVE-2019-20056 (#126), assertion failure problem, reported by @sleicasper.

    • Security fix for CVE-2019-20094 (#125), heap overflow problem, reported by @cuanduo.

    • Security fix for #124, illegal longjump() call problem, reported by @cuanduo.

    • Serucity fix for #74 and #123, access violation problem, reported by @HongxuChen and SuhwanSong.

    • Security fix for #122, heap overflow problem, reported by @SuhwanSong.

    • Security fix for CVE-2019-20023(#117, #119, #120), memory leaks problem, reported by @SuhwanSong and @gutiniao.

    • Strip first flag check in LZW compression function for issue #118, reported by @yoichi

    For more details, see below summary of vulnerabilities.

    | No. | assigned CVE | PR | patch | status | fixed on | comment |------|-------------------------------------|---------|-------------------|----------|---------|------- | #67 | CVE-2018-14072 CVE-2018-14073 | - | f94bc6f 84ed0bc | resolved | v1.8.2 | | #68 | - | - | 6a19d99 94a647c | resolved | v1.8.2 | | #69 | - | - | 0d70e04 | resolved | v1.8.2 | | #70 | - | - | 438188c | resolved | v1.8.2 | | #71 | - | - | 01c0bad ba21bb9 | resolved | v1.8.2 | | #72 | - | - | 570d6ae | released | v1.8.3 | | #73 | - | - | cb373ab 26ac06f | resolved | v1.8.4 | | #74 | - | - | 0b1e0b3 | resolved | v1.8.5 | | #75 | - | - | 7808a06 | resolved | v1.8.3 | | #76 | - | - | e3a4c0e 3c071b9 d7b2600 197d025 | partially resolved | partially fixed on v1.8.3 | | #77 | CVE-2018-19759 | #98 | 5f64fb1 | resolved | v1.8.3 | | #78 | CVE-2018-19761 | (#106) | (1377517) | resolved | v1.8.3 | *same as #105 | #79 | CVE-2018-19757 | #91 #94 | e903c93 a53c872 | resolved | v1.8.3 | | #80 | CVE-2018-19756 | #93 | d6e34fc | resolved | v1.8.3 | | #81 | CVE-2018-19762 | #92 | 9861272 | resolved | v1.8.3 | | #82 | CVE-2018-19763 | #95 | 614e761 | resolved | v1.8.3 | | #83 | CVE-2019-3573 CVE-2019-3574 | #99 | 9c013f2 68ecbc1 | resolved | v1.8.3 | | #85 | CVE-2019-11024 | - | b418f35 | resolved | v1.8.4 | | #88 | - | - | 7808a06 | resolved | v1.8.3 | | #89 | - | - | a516125 | resolved | v1.8.4 | | #90 | - | - | (1377517) | resolved | v1.8.3 | *same as #105 | #97 | - | - | (1377517) | resolved | v1.8.3 | *same as #105 | #102 | CVE-2019-19638 | #106 | e17c076 | resolved | v1.8.3 | | #103 | CVE-2019-19635 | #106 | 1377517 | resolved | v1.8.3 | | #104 | CVE-2019-19636 | #106 | bf46a7b | resolved | v1.8.3 | | #105 | CVE-2019-19637 | #106 | 1377517 | resolved | v1.8.3 | | #107 | - | - | 1d35033 | resolved | v1.8.4 | | #108 | (CVE-2019-19638) | (#106) | (e17c076) | resolved | v1.8.3 | *same as #102 | #109 | CVE-2019-19777 | (#93) | (d6e34fc) | resolved | v1.8.3 | *same as #80 | #110 | CVE-2019-19778 | (#95) | (614e761) | resolved | v1.8.3 | *same as #82 | #111 | - | (#106) | (1377517) | resolved | v1.8.3 | *same as #105 | #113 | - | (#93) | (aac1df6) | resolved | v1.8.3 | *same as #80 | #114 | - | - | (9d0a7ff) | resolved | v1.8.4 | *same as #116 | #116 | - | - | 9d0a7ff | resolved | v1.8.4 | | #117 | CVE-2019-20023 | - | b9a4175 | resolved | v1.8.5 | | #118 | - | - | 6367d2f | resolved | v1.8.4 | | #119 | (CVE-2019-20023) | - | b9a4175 | resolved | 1.8.5 | *same as #117 | #120 | (CVE-2019-20023) | - | b9a4175 | resolved | 1.8.5 | *same as #117 | #121 | - | | (6367d2f) | resolved | v1.8.4 | *same as #118 | #122 | - | | 598c8c8 | resolved | v1.8.5 | | #123 | - | | (0b1e0b3) | resolved | v1.8.5 | *same as #74 | #124 | - | | c1ef812 | resolved | v1.8.5 | | #125 | CVE-2019-20094 | | a18b378 | resolved | v1.8.5 | | #126 | CVE-2019-20096 | | 814f831 | resolved | v1.8.5 | | #127 | CVE-2019-20095 | | 5543354 | resolved | v1.8.5 |

    Source code(tar.gz)
    Source code(zip)
    libsixel-1.8.5.tar.gz(636.27 KB)
  • v1.8.4(Dec 18, 2019)

    • Security fix for CVE-2019-11024 (#85), recursive loop problem, reported by @Loginsoft-Research.

    • Security fix for #73, illegal memory access problem, reported by @HongxuChen.

    • Security fix for #89, core dumped issue, reported by @niugx.

    • Security fix for #107, large memory allocation problem, reported by @cuanduo.

    • Security fix for #114, heap-buffer-overflow problem, reported by @SuhwanSong.

    • Security fix for #116, heap-buffer-overflow problem, reported by @SuhwanSong.

    • Security fix for #118, heap-buffer-overflow problem, reported by @SuhwanSong.

    • Security fix for #121, heap-buffer-overflow problem, reported by @gutiniao

    For more details, see below summary of vulnerabilities.

    | No. | assigned CVE | PR | patch | status | fixed on | comment |------|-------------------------------------|---------|-------------------|----------|---------|------- | #67 | CVE-2018-14072 CVE-2018-14073 | - | f94bc6f 84ed0bc | resolved | v1.8.2 | | #68 | - | - | 6a19d99 94a647c | resolved | v1.8.2 | | #69 | - | - | 0d70e04 | resolved | v1.8.2 | | #70 | - | - | 438188c | resolved | v1.8.2 | | #71 | - | - | 01c0bad ba21bb9 | resolved | v1.8.2 | | #72 | - | - | 570d6ae | released | v1.8.3 | | #73 | - | - | cb373ab 26ac06f | resolved | v1.8.4 | | #74 | - | - | - | not resolved | - | | #75 | - | - | 7808a06 | resolved | v1.8.3 | | #76 | - | - | e3a4c0e 3c071b9 d7b2600 197d025 | partially resolved | partially fixed on v1.8.3 | | #77 | CVE-2018-19759 | #98 | 5f64fb1 | resolved | v1.8.3 | | #78 | CVE-2018-19761 | (#106) | (1377517) | resolved | v1.8.3 | *same as #105 | #79 | CVE-2018-19757 | #91 #94 | e903c93 a53c872 | resolved | v1.8.3 | | #80 | CVE-2018-19756 | #93 | d6e34fc | resolved | v1.8.3 | | #81 | CVE-2018-19762 | #92 | 9861272 | resolved | v1.8.3 | | #82 | CVE-2018-19763 | #95 | 614e761 | resolved | v1.8.3 | | #83 | CVE-2019-3573 CVE-2019-3574 | #99 | 9c013f2 68ecbc1 | resolved | v1.8.3 | | #85 | CVE-2019-11024 | - | b418f35 | resolved | v1.8.4 | | #88 | - | - | 7808a06 | resolved | v1.8.3 | | #89 | - | - | a516125 | resolved | v1.8.4 | | #90 | - | - | (1377517) | resolved | v1.8.3 | *same as #105 | #97 | - | - | (1377517) | resolved | v1.8.3 | *same as #105 | #102 | CVE-2019-19638 | #106 | e17c076 | resolved | v1.8.3 | | #103 | CVE-2019-19635 | #106 | 1377517 | resolved | v1.8.3 | | #104 | CVE-2019-19636 | #106 | bf46a7b | resolved | v1.8.3 | | #105 | CVE-2019-19637 | #106 | 1377517 | resolved | v1.8.3 | | #107 | - | - | 1d35033 | resolved | v1.8.4 | | #108 | (CVE-2019-19638) | (#106) | (e17c076) | resolved | v1.8.3 | *same as #102 | #109 | CVE-2019-19777 | (#93) | (d6e34fc) | resolved | v1.8.3 | *same as #80 | #110 | CVE-2019-19778 | (#95) | (614e761) | resolved | v1.8.3 | *same as #82 | #111 | - | (#106) | (1377517) | resolved | v1.8.3 | *same as #105 | #113 | - | (#93) | (aac1df6) | resolved | v1.8.3 | *same as #80 | #114 | - | - | (9d0a7ff) | resolved | v1.8.4 | *same as #116 | #116 | - | - | 9d0a7ff | resolved | v1.8.4 | | #117 | - | - | b9a4175 | patched | - | | #118 | - | - | 6367d2f | resolved | v1.8.4 | | #119 | - | - | b9a4175 | patched | - | *same as #117 | #120 | - | - | b9a4175 | patched | - | *same as #117 | #121 | - | | (6367d2f) | resolved | v1.8.4 | *same as |#118

    Source code(tar.gz)
    Source code(zip)
    libsixel-1.8.4.tar.gz(628.64 KB)
  • v1.8.3(Dec 14, 2019)

    • Security fix for CVE-2018-19757 (#79), NULL pointer dereference problem, reported by @nluedtke and fixed by @knok (#91, #94).

    • Security fix for CVE-2018-19762 (#81), heap-based buffer overflow problem, reported by @nluedtke and fixed by @knok (#92).

    • Security fix for CVE-2018-19756 (#80), heap-based buffer over-read problem, reported by @nluedtke and fixed by @knok (#93).

    • Security fix for CVE-2018-19763 (#82, reported by @nluedtke) and CVE-2019-19778 (#110, reported by @SuhwanSong), heap-based buffer over-read problem, fixed by @knok (#95).

    • Security fix for CVE-2018-19761, illegal address access, fixed by @knok (#96).

    • Security fix for CVE-2018-19759, heap-based buffer over-read problem, fixed by @knok (#98).

    • Security fix for CVE-2019-3753 (#83), infinite loop problem, reported by @cool-tomato and fixed by @knok (#99).

    • Security fix for CVE-2018-19759 (#102), heap-based buffer over-read that will cause a denial of service. reported and fixed by @YourButterfly. (#106)

    • Security fix for CVE-2019-19635 (#103), heap-based buffer overflow, reported and fixed by @YourButterfly. (#106)

    • Security fix for CVE-2019-19636 (#104) and CVE-2019-19637 (#105), integer overflow problem. reported and fixed by @YourButterfly. (#106)

    • gif loader: check LZW code size (Issue #75), Thanks to @HongxuChen. https://github.com/saitoha/libsixel/commit/7808a06b88c11dbc502318cdd51fa374f8cd47ee

    • core: Fix a global-buffer-overflow problem (Issue #72), Thanks to @fgeek. https://github.com/saitoha/libsixel/commit/c868b59ec89bdb24c42a0de89e5319a989076c66

    • core: Fix unexpected hangs/performance issues (Issue #76), Thanks to @HongxuChen. https://github.com/saitoha/libsixel/commit/88561b7a810017b91d26b6273323dde4b6f9b273 https://github.com/saitoha/libsixel/commit/2d3d9ffe8ab886b7bc670fd896d63c628436cc66 https://github.com/saitoha/libsixel/commit/c9363cd1d5929e1d721af9f09633061dfa8152fe

    Source code(tar.gz)
    Source code(zip)
    libsixel-1.8.3.tar.gz(626.74 KB)
  • v1.8.2(Jul 22, 2018)

    This release provides some security updates.

    • core: Fix memory leak problems(#67, CVE-2018-14072, CVE-2018-14073), thanks to @fCorleone. https://github.com/saitoha/libsixel/commit/f94bc6fec696abd77be275226f28409602bd1f27 https://github.com/saitoha/libsixel/commit/84ed0bc35e273ebd0a7fbc9d8f8669f7cf5f5612

    • core: Fix some heap buffer-overflow problems(#68, #69, #70, #71), thanks to @fgeek. https://github.com/saitoha/libsixel/commit/6a19d99f95dafbbb50facf9267497afbcfba5731 https://github.com/saitoha/libsixel/commit/0d70e046437370c86696f2ed38ac0413855d98ce https://github.com/saitoha/libsixel/commit/438188c1f8b418a38674364cf5c126ef3ed4166a https://github.com/saitoha/libsixel/commit/ba21bb94d68f8bf7dc590400a707753f5d5c4709

    • man: Fix a typo (#66), thanks to @tsutsui. https://github.com/saitoha/libsixel/commit/cf4728159c6493b64ac7bf187290698ca97cce82

    Source code(tar.gz)
    Source code(zip)
    libsixel-1.8.2.tar.gz(4.55 MB)
  • v1.8.1(Jun 9, 2018)

  • v1.8.0(Jun 7, 2018)

                  ------------------------------
                   What's new in libsixel-1.8 ?
                  ------------------------------
    
    • core: Upgrade stb_image to 2.19.

    • core: Introduce new dithering method, a_dither / x_dither (http://pippin.gimp.org/a_dither/). Thanks to @hodefoting. https://github.com/saitoha/libsixel/pull/53

    • core: Fix wrong HLS color handling. https://github.com/saitoha/libsixel/commit/0fb35d22e7ba4ed8bce3be42791e6b39c3187b89

    • core: Improve quality of 15bpp(hi-color mode) dither. https://github.com/saitoha/libsixel/commit/42f34283defea67c2d6294af4bd7dcb4fdf9f046

    • img2sixel: Allow a deferred clear code in a GIF format GIF decoder must do nothing when the table is full. See Section "DEFERRED CLEAR CODE IN LZW COMPRESSION" in https://www.w3.org/Graphics/GIF/spec-gif89a.txt. Thanks to @mame. https://github.com/saitoha/libsixel/pull/63

    • img2sixel: Marks -D option (read source images from stdin continuously) as deprecated https://github.com/saitoha/libsixel/commit/9c8ffa62203899d866fc28e3ab7c6dfd9a0019b1

    • Some bug fixes and minor improvements. Thanks to @set135, @ttdoda.

    • Announcement for package maintainers: Immutable tarball is provided, because GitHub auto-generated tarball may be not immutable.

      https://github.com/saitoha/libsixel/releases/download/v1.8.0/libsixel-1.8.0.tar.gz

      For details, see https://github.com/saitoha/libsixel/issues/64 .

    Source code(tar.gz)
    Source code(zip)
    libsixel-1.8.0.tar.gz(4.55 MB)
  • v1.7.3(Jun 2, 2018)

    We additionally provide immutable tarball: https://github.com/saitoha/libsixel/releases/download/v1.7.3/libsixel-1.7.3.tar.gz

    According to Issue #64, GitHub auto-generated tarball(https://github.com/saitoha/libsixel/archive/v1.7.3.tar.gz) may be not immutable.

    Source code(tar.gz)
    Source code(zip)
    libsixel-1.7.3.tar.gz(4.54 MB)
Owner
Hayaki Saito
Hayaki Saito
Demo of using Auto Encoder for Image Denoising

Demo of using Auto Encoder for Image Denoising

null 2 Aug 4, 2022
Multi-view 3D reconstruction using neural rendering. Unofficial implementation of UNISURF, VolSDF, NeuS and more.

Multi-view 3D reconstruction using neural rendering. Unofficial implementation of UNISURF, VolSDF, NeuS and more.

Jianfei Guo 683 Jan 4, 2023
A scalable implementation of WobblyStitcher for 3D microscopy images

WobblyStitcher Introduction A scalable implementation of WobblyStitcher Dependencies $ python -m pip install numpy scikit-image Visualization ImageJ

CSE Lab, ETH Zurich 7 Jul 25, 2022
Python implementation of image filters (such as brightness, contrast, saturation, etc.)

PyPhotoshop Python implementation of image filters Use Python to adjust brightness and contrast, add blur, and detect edges! Follow along tutorial: ht

Kylie 87 Dec 15, 2022
A pure python implementation of the GIMP XCF image format. Use this to interact with GIMP image formats

Pure Python implementation of the GIMP image formats (.xcf projects as well as brushes, patterns, etc)

FHPyhtonUtils 8 Dec 30, 2022
A quick and dirty QT Statusbar implementation for grabbing GIFs from Tenor, since there is no offical or unofficial one I found. This was intended for use under Linux, however it was also functional enough on MacOS.

Statusbar-TenorGIF App for Linux A quick and dirty QT Statusbar implementation for grabbing GIFs from Tenor, since there is no offical one and I didnt

Luigi DaVinci 1 Nov 1, 2021
A proof-of-concept implementation of a parallel-decodable PNG format

mtpng A parallelized PNG encoder in Rust by Brion Vibber [email protected] Background Compressing PNG files is a relatively slow operation at large imag

Brion Vibber 193 Dec 16, 2022
A functional and efficient python implementation of the 3D version of Maxwell's equations

py-maxwell-fdfd Solving Maxwell's equations via A python implementation of the 3D curl-curl E-field equations. This code contains additional work to e

Nathan Zhao 12 Dec 11, 2022
Godzilla traffic decoder Godzilla Decoder 是一个用于 哥斯拉Godzilla 加密流量分析的辅助脚本。

Godzilla Decoder 简介 Godzilla Decoder 是一个用于 哥斯拉Godzilla 加密流量分析的辅助脚本。 Godzilla Decoder 基于 mitmproxy,是mitmproxy的addon脚本。 目前支持 哥斯拉3.0.3 PhpDynamicPayload的

He Ruiliang 40 Dec 25, 2022
Official PyTorch implementation for Generic Attention-model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers, a novel method to visualize any Transformer-based network. Including examples for DETR, VQA.

PyTorch Implementation of Generic Attention-model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers 1 Using Colab Please notic

Hila Chefer 489 Jan 7, 2023
An implementation of a sequence to sequence neural network using an encoder-decoder

Keras implementation of a sequence to sequence model for time series prediction using an encoder-decoder architecture. I created this post to share a

Luke Tonin 195 Dec 17, 2022
Ultra fast JSON decoder and encoder written in C with Python bindings

UltraJSON UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 3.6+. Install with pip: $ python -m pip insta

null 3.9k Dec 31, 2022
Ultra fast JSON decoder and encoder written in C with Python bindings

UltraJSON UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 3.6+. Install with pip: $ python -m pip insta

null 3.9k Jan 2, 2023
simplejson is a simple, fast, extensible JSON encoder/decoder for Python

simplejson simplejson is a simple, fast, complete, correct and extensible JSON <http://json.org> encoder and decoder for Python 3.3+ with legacy suppo

null 1.5k Dec 31, 2022
simplejson is a simple, fast, extensible JSON encoder/decoder for Python

simplejson simplejson is a simple, fast, complete, correct and extensible JSON <http://json.org> encoder and decoder for Python 3.3+ with legacy suppo

null 1.5k Jan 5, 2023
[ICCV 2021] Encoder-decoder with Multi-level Attention for 3D Human Shape and Pose Estimation

MAED: Encoder-decoder with Multi-level Attention for 3D Human Shape and Pose Estimation Getting Started Our codes are implemented and tested with pyth

ZiNiU WaN 176 Dec 15, 2022
DeepLabv3+:Encoder-Decoder with Atrous Separable Convolution语义分割模型在tensorflow2当中的实现

DeepLabv3+:Encoder-Decoder with Atrous Separable Convolution语义分割模型在tensorflow2当中的实现 目录 性能情况 Performance 所需环境 Environment 注意事项 Attention 文件下载 Download

Bubbliiiing 31 Nov 25, 2022
Code for CodeT5: a new code-aware pre-trained encoder-decoder model.

CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation This is the official PyTorch implementation

Salesforce 564 Jan 8, 2023
A morse code encoder and decoder utility.

morsedecode A morse code encoder and decoder utility. Installation Install it via pip: pip install morsedecode Alternatively, you can use pipx to run

Tushar Sadhwani 2 Dec 25, 2021
This repository contains the data and code for the paper "Diverse Text Generation via Variational Encoder-Decoder Models with Gaussian Process Priors" (SPNLP@ACL2022)

GP-VAE This repository provides datasets and code for preprocessing, training and testing models for the paper: Diverse Text Generation via Variationa

Wanyu Du 18 Dec 29, 2022