Skip to content

Added metadata string is wrong and not parsed correctly in kiwix-serve #8

Closed

Description

@jdcaballerov
  • there's an unsafe use of memory. if you use the same variable for different articles, the articles count of the zim there are added to gets messed-up
creator = pyzim.ZimCreator("z1.zim")
article = pyzim.ZimArticle(url="1", title="Page 1", content="<html><head></head><body><h1>Welcome to page 1</h1></body></html>")
creator.add_article(article)
creator.finalise()
# T:0; A:4; RA:0; CA:4; UA:0; FA:0; IA:4; C:0; CC:0; UC:0; WC:3
# T:0; Generate cluster offsets
# T:0; ResolveRedirectIndexes
# Resolve redirect
# T:0; Set article indexes
# set index
# T:0; Resolve mimetype
# T:0; create title index
# T:0; 6 title index created
# T:0; 2 clusters created
# T:0; fill header
# T:0; write zimfile :
# T:0;  write header
# T:0;  write mimetype list
# T:0;  write url prt list
# T:0;  write title index
# T:0;  write directory entries
# T:0;  write cluster offset list
# T:0;  write cluster data
# T:0;  write checksum
# T:0; finish
reader = pyzim.ZimReader("z1.zim")
reader.get_article_count()  # 6
reader.get_namespaces_count("A")  # 1 (OK)

creator2 = pyzim.ZimCreator("z2.zim")
article = pyzim.ZimArticle(url="2", title="Page 2", content="<html><head></head><body><h1>Welcome to page 2</h1></body></html>")
creator2.add_article(article)
creator2.finalise()
# T:0; A:4; RA:0; CA:4; UA:0; FA:0; IA:4; C:0; CC:0; UC:0; WC:1
# T:0; Generate cluster offsets
# T:0; ResolveRedirectIndexes
# Resolve redirect
# T:0; Set article indexes
# set index
# T:0; Resolve mimetype
# T:0; create title index
# T:0; 6 title index created
# T:0; 2 clusters created
# T:0; fill header
# T:0; write zimfile :
# T:0;  write header
# T:0;  write mimetype list
# T:0;  write url prt list
# T:0;  write title index
# T:0;  write directory entries
# T:0;  write cluster offset list
# T:0;  write cluster data
# T:0;  write checksum
# T:0; finish
reader2 = pyzim.ZimReader("z2.zim")
reader2.get_article_count()  # 6
reader2.get_namespaces_count("A")  # 1 (OK)

Now add both to kiwix-serve and you'll see that z1 has 1 article while z2 has 2 articles. If we were to reuse that same article many times, we'd the the counter increase by that number.

I don't understand completely what's kiwix-serve? can you give me the whole example ?

Activity

  1. changed the title [-]Added metadata string is not parsed correctly in kiwix-serve[/-] [+]Added metadata string is wrong and not parsed correctly in kiwix-serve[/+] on Apr 9, 2020
  2. jdcaballerov commented on Apr 10, 2020

    @jdcaballerov
    ContributorAuthor

    The issue was present because ZimCreator defined class members: _article_counter and a _metadata dict.

    Class members are shared by all the instances. Cython requires initializing instance members in __cinit__. A deep copy of the parameters is performed for _metadata and a new defaultdict is created for _article_counter in __cinit__(). Each ZimCreator instance will have it's own metadata and counter.

    Fixed b4efd90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions