Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docx writer crashes on invalid tables #8102

Open
tarleb opened this issue Jun 3, 2022 · 3 comments
Open

Docx writer crashes on invalid tables #8102

tarleb opened this issue Jun 3, 2022 · 3 comments

Comments

@tarleb
Copy link
Collaborator

tarleb commented Jun 3, 2022

The docx writer crashes with error pandoc: Error in array index when processing an inconsistent/invalid table that has fewer cells in a row than expected. This only shows when processing JSON or native input, as in those cases the tables are not necessarily normalized:

[ Table
    ( "" , [] , [] )
    (Caption Nothing [])
    [ ( AlignLeft , ColWidth 0.5 )
    , ( AlignLeft , ColWidth 0.5 )
    ]
    (TableHead ( "" , [] , [] ) [])
    [ TableBody
        ( "" , [] , [] )
        (RowHeadColumns 1)
        []
        [ Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] )
                AlignLeft
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "single" ] ]
            ]
        , Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] )
                AlignLeft
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "one" ] ]
            , Cell
                ( "" , [] , [] )
                AlignLeft
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "two" ] ]
            ]
        ]
    ]
    (TableFoot ( "footer" , [] , [] ) [])
]

The second row in the table above is necessary to trigger the error.

@jgm
Copy link
Owner

jgm commented Jun 3, 2022

I'd guess it's T.P.Writers.Docx.Table l. 195, with the ! indexing an array.
We shouldn't assume that the array will have something at that index.

@tarleb tarleb closed this as completed in cc2849c Jun 4, 2022
@tustin2121
Copy link

This is still an issue I'm having in the latest version (3.6.1). I was writing a custom table output filter and got the col_span and row_span backwards in the output (so it was trying to span 5 rows instead of 5 columns), and the docx writer just crashed with this error message and nothing more useful.

I managed to finally fix my filter thanks to this bug writeup, but I'm still annoyed that pandoc didn't provide any useful feedback on what was wrong with the output. At least prior to getting this error, I got errors about invalid row formats in $.block[18][0][0] and the like, which while cryptic at least was some feedback that I was able to use to look through the json output.

@jgm jgm reopened this Dec 30, 2024
@jgm
Copy link
Owner

jgm commented Dec 30, 2024

Re-opening because @tarleb's fix didn't address the Docx writer's assumption noted above. I think we should change something there, too; certainly we shouldn't be exiting with an array index error.

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

No branches or pull requests

3 participants