Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 07-23-2014, 01:49 PM   #16
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Now do the following little experiment,

u_genre = eval(u_genre)
kovidgoyal is online now   Reply With Quote
Old 07-23-2014, 02:09 PM   #17
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
Okay. Here it is, both in IDLE and then in ui.py:


This was the ui.py code:

if isinstance(u_genre, bytes):
print("u_genre is bytes", u_genre)
else:
if isinstance(u_genre, unicode): #e.g. u'N\xe3o-fic\xe7\xe3o'
print("u_genre is utf8", u_genre)
else:
print("u_genre is something else...", u_genre)
print("u_genre before repr(u_genre) ", u_genre)
u_test = u_genre
u = (repr(u_test))
print("u_genre clone after repr(clone) ", u)
print("u_genre before eval(u_genre)")
u_test = u_genre
u_test = eval(u_test) #<====== eval
print("after eval: ", u_test) #<====== failed. Line 191


------------------ print output ------------------------------------------------
calibre 1.45 [64bit] isfrozen: True is64bit: True
Windows-7-6.1.7601-SP1 Windows ('64bit', 'WindowsPE')
('Windows', '7', '6.1.7601')
Python 2.7.5
Windows: ('7', '6.1.7601', 'SP1', 'Multiprocessor Free')
Traceback (most recent call last):
File "site-packages\calibre\gui2\proceed.py", line 123, in do_ask_question
File "calibre_plugins.derive_genres.ui", line 191, in _proceed_with_updating_genres
IOError: [Errno 0] Error


I did the same thing in IDLE, and got a failure, but only after it printed it correctly:

>>> u_genre = eval(u_genre)
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "<string>", line 1
Não-ficção <<<<<<<<============================= CORRECT
^
SyntaxError: invalid syntax

------------------------------------------------------------------------------------
DaltonST is offline   Reply With Quote
Advert
Old 07-23-2014, 02:17 PM   #18
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
eval(xxx) Fixed The Problem

Kovid,

I changed the code to use the eval statement you specified, but did NOT print it to avoid a runtime error. It worked! Thank you for solving this. Great job.
Attached Thumbnails
Click image for larger version

Name:	solution_is_to_use_eval.JPG
Views:	255
Size:	43.5 KB
ID:	125753  
DaltonST is offline   Reply With Quote
Old 07-23-2014, 02:17 PM   #19
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I give up, your output is completely self conflicting.

In the next to last post you have

print repr(u_genre) --> u"u'Fiction:General'"

If that is the case there is no way that eval(u_genre) can fail.

Code:
>>> a = u'N\\xe3o-fic\\xe7\\xe3o'
>>> print (a)
N\xe3o-fic\xe7\xe3o
>>> b = repr(a)
>>> print (b)
u'N\\xe3o-fic\\xe7\\xe3o'
>>> print (repr(b))
"u'N\\\\xe3o-fic\\\\xe7\\\\xe3o'"
>>> eval(b) == a
True
>>>
I have no idea what you are doing, but it isn't what you say you're doing.
kovidgoyal is online now   Reply With Quote
Old 07-23-2014, 02:19 PM   #20
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
This is not a fix, it is just proof that u_genre is not what you think it is. It is for some reason already the result of calling repr() on the original string. You need to figure out why that is and solve it at the source.

Using eval() in production code is a very bad idea, it is an arbitrary code execution loophole.
kovidgoyal is online now   Reply With Quote
Advert
Old 07-23-2014, 02:20 PM   #21
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
Good Job.

Kovid, thanks again for figuring out that eval() solves the problem.

I did not use repr() on it prior to using eval().

I used repr() on a clone of u_genre.

I used eval() directly on u_genre.

Last edited by DaltonST; 07-23-2014 at 02:23 PM.
DaltonST is offline   Reply With Quote
Reply

Tags
custcol['#value#'], set_user_metadata, unicode


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PRS-T1 PRS-T1 & Asian Fonts/Unicode komugi Sony Reader 20 10-05-2013 11:49 PM
RegEx & Unicode capnm Library Management 14 12-01-2011 08:23 PM


All times are GMT -4. The time now is 05:04 AM.


MobileRead.com is a privately owned, operated and funded community.