Quantcast

[Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1044&from=L21haW4-

Antonio OREFICE reported a new bug.

Summary
-------

Gambas should trow an error or at least a warning when loading corrupted images

Type             : Bug
Priority         : Medium
Gambas version   : Unknown
Product          : Unknown


Description
-----------

See the following code:

Public Sub Form_Open()
  Dim myimage As New Image
  Dim mydata As String
  Dim tmpfile As String = "/tmp/myimage.jpg"
  myimage.Resize(100, 100)
  myimage.Fill(Color.black)
  myimage.Save(tmpfile)
  mydata = File.Load(tmpfile)
  mydata = Left(mydata, Len(mydata) - 100)
  File.Save(tmpfile, mydata)
  Try myimage = Image.Load(tmpfile)
  If Error Then
    Debug "Error while loading the image"
  Endif
End

No Error is catched, because gambas loads the corrupted image.
Still, in the console log something throws the error/warning
"Corrupt JPEG data: premature end of data segment"

But, actually, i can't see a way to handle that at code level.

Is there a workaround or this is in the need of a fix?

Thanks.


System information
------------------

[System]
Gambas=3.9.1
OperatingSystem=Linux
Kernel=4.8.7-1-ARCH
Architecture=x86_64
Distribution=Arch Linux
Desktop=KDE5
Theme=Breeze
Language=it_IT.utf8
Memory=7933M

[Libraries]
Cairo=libcairo.so.2.11400.6
Curl=libcurl.so.4.4.0
DBus=libdbus-1.so.3.14.8
GStreamer=libgstreamer-0.10.so.0.30.0
GStreamer=libgstreamer-1.0.so.0.1001.0
GTK+2=libgtk-x11-2.0.so.0.2400.31
GTK+3=libgtk-3.so.0.2200.4
OpenGL=libGL.so.1.0.0
OpenGL=libGL.so.1.2.0
Poppler=libpoppler.so.63.0.0
QT4=libQtCore.so.4.7.4
QT4=libQtCore.so.4.8.7
QT5=libQt5Core.so.5.3.2
QT5=libQt5Core.so.5.7.0
SDL=libSDL-1.2.so.0.11.4
SQLite=libsqlite3.so.0.8.6

[Environment]
ANT_HOME=/usr/share/apache-ant
Automoc4_DIR=/usr/lib/automoc4
CCACHEPATH=/usr/lib/ccache/bin
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus
DESKTOP_SESSION=/usr/share/xsessions/plasma
DISPLAY=:0
EDITOR=nano
GB_GUI=gb.qt5
GS_LIB=<home>/.fonts
GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:<home>/.gtkrc-2.0:<home>/.config/gtkrc-2.0
GTK_MODULES=canberra-gtk-module
GTK_RC_FILES=/etc/gtk/gtkrc:<home>/.gtkrc:<home>/.config/gtkrc
HG=/usr/bin/hg
HISTCONTROL=ignoredups
HISTSIZE=50000
HOME=<home>
INFINALITY_FT=
INFINALITY_FT_AUTOFIT_FORCE_SLIGHT_HINTING=true
INFINALITY_FT_AUTOHINT_HORIZONTAL_STEM_DARKEN_STRENGTH=0
INFINALITY_FT_AUTOHINT_INCREASE_GLYPH_HEIGHTS=false
INFINALITY_FT_AUTOHINT_SNAP_STEM_HEIGHT=0
INFINALITY_FT_AUTOHINT_VERTICAL_STEM_DARKEN_STRENGTH=25
INFINALITY_FT_BOLD_EMBOLDEN_X_VALUE=0
INFINALITY_FT_BOLD_EMBOLDEN_Y_VALUE=0
INFINALITY_FT_BRIGHTNESS=0
INFINALITY_FT_CHROMEOS_STYLE_SHARPENING_STRENGTH=0
INFINALITY_FT_CONTRAST=-20
INFINALITY_FT_FILTER_PARAMS=7 25 44 25 7
INFINALITY_FT_FRINGE_FILTER_STRENGTH=0
INFINALITY_FT_GAMMA_CORRECTION=0 100
INFINALITY_FT_GLOBAL_EMBOLDEN_X_VALUE=0
INFINALITY_FT_GLOBAL_EMBOLDEN_Y_VALUE=0
INFINALITY_FT_GRAYSCALE_FILTER_STRENGTH=0
INFINALITY_FT_STEM_ALIGNMENT_STRENGTH=0
INFINALITY_FT_STEM_FITTING_STRENGTH=0
INFINALITY_FT_STEM_SNAPPING_SLIDING_SCALE=0
INFINALITY_FT_USE_KNOWN_SETTINGS_ON_SELECTED_FONTS=true
INFINALITY_FT_USE_VARIOUS_TWEAKS=true
INFINALITY_FT_WINDOWS_STYLE_SHARPENING_STRENGTH=0
INTEL_BATCH=1
KDE_FULL_SESSION=true
KDE_MULTIHEAD=false
KDE_SESSION_UID=0
KDE_SESSION_VERSION=5
KMIX_PULSEAUDIO_DISABLE=1
KWIN_NVIDIA_HACK=1
LANG=it_IT.utf8
LANGUAGE=en_US
LC_COLLATE=C
LD_LIBRARY_PATH=/usr/local/lib/icu-55/
LESS_TERMCAP_mb=
LESS_TERMCAP_md=
LESS_TERMCAP_me=
LESS_TERMCAP_se=
LESS_TERMCAP_so=
LESS_TERMCAP_ue=
LESS_TERMCAP_us=
LOGNAME=<user>
LS_COLORS=rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:
MAIL=/var/spool/mail<home>
MOZ_DISABLE_PANGO=1
MOZ_PLUGIN_PATH=/usr/lib/mozilla/plugins
NXDIR=/usr/lib/nx
OOO_FORCE_DESKTOP=gnome
PATH=/usr/lib/ccache/bin:/usr/lib/nx/bin:/usr/lib/hardening-wrapper/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/opt/cuda/bin:/opt/depot_tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:<home>/scripts:/home<home>/scripts/DominioNT/:/usr/local/bin
PS4=+
PWD=<home>
QT_AUTO_SCREEN_SCALE_FACTOR=0
QT_GRAPHICSSYSTEM=raster
QT_NO_GLIB=1
QT_QPA_PLATFORMTHEME=kde
SESSION_MANAGER=local/<hostname>:@/tmp/.ICE-unix/2158,unix/<hostname>:/tmp/.ICE-unix/2158
SHELL=/bin/bash
SHLVL=1
TZ=:/etc/localtime
USER=<user>
WINEARCH=win32
WINEDLLOVERRIDES=winemenubuilder.exe=d
XAUTHORITY=/tmp/xauth-0-_0
XCURSOR_SIZE=0
XCURSOR_THEME=Jimmac
XDG_CURRENT_DESKTOP=KDE
XDG_DATA_DIRS=/usr/share:/usr/share:/usr/local/share
XDG_DESKTOP_DIR=$HOME/Desktop"
XDG_RUNTIME_DIR=/run/user/0
XDG_SEAT=seat0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_SESSION_CLASS=user
XDG_SESSION_DESKTOP=KDE
XDG_SESSION_ID=c2
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SESSION_TYPE=x11
XDG_VTNR=7
_=/usr/lib/kf5/start_kdeinit_wrapper
__GLVND_DISALLOW_PATCHING=1
__GL_SHADER_DISK_CACHE=1
__GL_YIELD=USLEEP



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1044&from=L21haW4-

Comment #1 by Fabien BODARD:

In fact you can check if "myImage" contain an image object :

Public Sub Form_Open()
  Dim myimage As New Image
  Dim mydata As String
  Dim tmpfile As String = "/tmp/myimage.jpg"
  myimage.Resize(100, 100)
  myimage.Fill(Color.black)
  myimage.Save(tmpfile)
  mydata = File.Load(tmpfile)
  mydata = Left(mydata, Len(mydata) - 100)
  File.Save(tmpfile, mydata)
  Try myimage = Image.Load(tmpfile)
  If Error Then
    Debug "Error while loading the image"
  Endif

  if not myImage then Debug "Image is not loaded"

End


Is this way solve your problem ?

Fabien BODARD changed the state of the bug to: NeedsInfo.



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

bugtracker
In reply to this post by bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1044&from=L21haW4-

Comment #2 by Antonio OREFICE:

It does not.
If you try to display the corrupted image, it displays a corrupted image :)



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

bugtracker
In reply to this post by bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1044&from=L21haW4-

Comment #3 by Fabien BODARD:

After a short test ... no



It seem to be not possible to capture the loader error.



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

bugtracker
In reply to this post by bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1044&from=L21haW4-

Comment #4 by BenoƮt MINISINI:

Please provide a project that reproduces the bug.



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

bugtracker
In reply to this post by bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1044&from=L21haW4-

Comment #5 by Antonio OREFICE:

The example provided by Fabien does indeed reproduce the "bug", but i made another one, attached.
I also noticed that with gb.gtk it does (prints "image is corrupted"), while gb.qt4 and gb.qt5 always print "Image is fine"

Public Sub Form_Open()
  Dim hFile As File
  Dim mydata As Byte[]
  Dim sFileName As String = "/tmp/image.jpg"
  Dim img As New Image(640, 480, Color.black) 'make a black image
  Dim i As Long
  Dim bByte As Byte
  Dim bBytes As New Byte[]
  Dim iLen As Long
  img.Save(sFileName) 'save it to disk
 
  hFile = Open sFileName For Read
 
  iLen = Stat(sFileName).Size
 
  For i = 0 To iLen - 1 'read the image file in memory
    Read #hFile, bByte
    bBytes.Add(bByte)
  Next 'i
 
  hFile.Close()
  Kill sFileName 'delete the image file

  hFile = Open sFileName For Read Write Create


  For i = 0 To ((iLen - 1) Div 2) 'write it to disk again, but only the first half
    Write #hFile, bBytes[i] As Byte
  Next 'i
 
  hFile.Close()
 
  Try img = Image.Load(sFileName) 'try to load the corrupted image
 
  If Error Then
    Print "Image is corrupted" '<--- this is printed with gtk2 and gtk3
      Else
    Print "Image is fine" '<--- this is printed with qt4 and qt5
  Endif

End



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

bugtracker
In reply to this post by bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1044&from=L21haW4-

Antonio OREFICE added an attachment:

corruptimage-0.0.1.tar.gz



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

bugtracker
In reply to this post by bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1044&from=L21haW4-

Comment #6 by Antonio OREFICE:

Ops, the previous attached project was using gtk, so it works, i've just attached one that does not because is using qt5.
In the IDE console output, you'll see:

Corrupt JPEG data: premature end of data segment
Image is fine



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

bugtracker
In reply to this post by bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1044&from=L21haW4-

Antonio OREFICE added an attachment:

corruptimage-qt-0.0.1.tar.gz



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Loading...