After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 777894 - Avoid mixing files with paths
Avoid mixing files with paths
Status: RESOLVED FIXED
Product: libgxps
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: libgxps maintainers
libgxps maintainers
Depends on:
Blocks:
 
 
Reported: 2017-01-29 08:52 UTC by Carlos Garcia Campos
Modified: 2017-02-20 16:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
parse-utils: instead of using GFile use paths and canonalize them (3.67 KB, patch)
2017-01-29 19:02 UTC, Ignacio Casal Quinteiro (nacho)
none Details | Review
parse-utils: instead of using GFile use paths and canonalize them (3.55 KB, patch)
2017-02-20 15:58 UTC, Ignacio Casal Quinteiro (nacho)
committed Details | Review

Description Carlos Garcia Campos 2017-01-29 08:52:31 UTC
This was fixed in 8f04b292c0e551e2ba8dba2c77012699e40685c7, but I've just reverted it because it broke structre paths containing '..', like:

/Documents/1/Structure/DocStructure.struct ../FixedDoc.fdoc#PG_441_LNK_2464

this is now resolved as:

/Documents/1/Structure/../FixedDoc.fdoc#PG_441_LNK_2464

and it used to be resolved as:

/Documents/1/FixedDoc.fdoc#PG_441_LNK_2464

We need this, because we compare paths directly, that's why we need to resolve them. The reason why we used GFile as because g_file_for_path canonicalize the path. The problem is that the method canonicalize_filename is private in glib and uses G_DIR_SEPARATOR_S and G_IS_DIR_SEPARATOR. A possible solution wold be to keep the existing code and then replace \ with / #ifdef G_OS_WIN32. Or could do the canonicalization ourselves, by copying the canonicalize_filename() method and replacing all G_DIR_SEPARATOR_S by "/" and G_IS_DIR_SEPARATOR by p == '/'.
Comment 1 Carlos Garcia Campos 2017-01-29 08:53:27 UTC
Btw, you can reproduce this by opening the XPS spec in evince, for example. You sere the outline is collapsed and you and error if you try to navigate it.
Comment 2 Ignacio Casal Quinteiro (nacho) 2017-01-29 19:02:25 UTC
Created attachment 344496 [details] [review]
parse-utils: instead of using GFile use paths and canonalize them

This takes the method from glib to canonalize the paths just
that instead of using G_DIR_SEPARATOR it always uses / since
we want / for all the platforms.
Comment 3 Ignacio Casal Quinteiro (nacho) 2017-01-29 19:03:50 UTC
Carlos I went for the option of copying the method since IMHO it is more correct. Also when discussing with pbor the other option would endup being a big hack.
Comment 4 Carlos Garcia Campos 2017-02-18 07:46:23 UTC
Review of attachment 344496 [details] [review]:

::: libgxps/gxps-parse-utils.c
@@ +428,3 @@
+	 */
+	i = 0;
+	for (p = start - 1; (p >= canon) && G_IS_DIR_SEPARATOR (*p); p--)

Does this work in windows? Shouldn't we also check here if *p == '/' explicitly instead of using G_IS_DIR_SEPARATOR?
Comment 5 Ignacio Casal Quinteiro (nacho) 2017-02-18 07:55:22 UTC
(In reply to Carlos Garcia Campos from comment #4)
> Review of attachment 344496 [details] [review] [review]:
> 
> ::: libgxps/gxps-parse-utils.c
> @@ +428,3 @@
> +	 */
> +	i = 0;
> +	for (p = start - 1; (p >= canon) && G_IS_DIR_SEPARATOR (*p); p--)
> 
> Does this work in windows? Shouldn't we also check here if *p == '/'
> explicitly instead of using G_IS_DIR_SEPARATOR?

We can change it if you want but on windows it is defined like this:
#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')

so we should be safe
Comment 6 Ignacio Casal Quinteiro (nacho) 2017-02-20 15:58:21 UTC
Created attachment 346270 [details] [review]
parse-utils: instead of using GFile use paths and canonalize them

This takes the method from glib to canonalize the paths just
that instead of using G_DIR_SEPARATOR it always uses / since
we want / for all the platforms.
Comment 7 Ignacio Casal Quinteiro (nacho) 2017-02-20 15:59:34 UTC
(In reply to Ignacio Casal Quinteiro (nacho) from comment #5)
> (In reply to Carlos Garcia Campos from comment #4)
> > Review of attachment 344496 [details] [review] [review] [review]:
> > 
> > ::: libgxps/gxps-parse-utils.c
> > @@ +428,3 @@
> > +	 */
> > +	i = 0;
> > +	for (p = start - 1; (p >= canon) && G_IS_DIR_SEPARATOR (*p); p--)
> > 
> > Does this work in windows? Shouldn't we also check here if *p == '/'
> > explicitly instead of using G_IS_DIR_SEPARATOR?
> 
> We can change it if you want but on windows it is defined like this:
> #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
> 
> so we should be safe

I took your advice and changed it too since it is definitely more correct.
Comment 8 Ignacio Casal Quinteiro (nacho) 2017-02-20 16:00:15 UTC
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.